-
Book Overview & Buying
-
Table Of Contents
Pandas Cookbook - Third Edition
By :
At this point, we have reviewed many of the “first-class” data types built into pandas, while highlighting some rough edges and inconsistencies that plague them. Despite those issues, the types baked into pandas can take you a long way in your data journey.
But there are still cases where the pandas types are not suitable, with a common case being interoperability with databases. Most databases have distinct DATE and DATETIME types, so the fact that pandas only offers a DATETIME type can be disappointing to users fluent in SQL.
Fortunately, the Apache Arrow project defines a true DATE type. Starting in version 2.0, pandas users can start leveraging Arrow types exposed through the PyArrow library.
To construct PyArrow types in pandas directly, you will always provide a dtype= argument of the pd.ArrowDtype(XXX) form, replacing XXX with the appropriate PyArrow type. The DATE type in PyArrow is called pa.date32():
ser...