Can I specify column types while saving a pandas DataFrame to a pen?

Currently, if a column has only zeros, an exception is thrown with an error:

Invalid: could not specify an array of object types, were empty

Can you specify the type of column that will be used instead of deducing the type?

Versions:

feather-format==0.3.1
pandas==0.19.1

Code example:

feather.write_dataframe(pandas.DataFrame([None]*5), '/tmp/test.feather')
+4
source share
1 answer

Change (or replace) Noneto numpy.nan, and it will work:

In [22]: feather.write_dataframe(pd.DataFrame([np.nan]*5), 'd:/temp/test.feather')

In [23]: feather.read_dataframe('d:/temp/test.feather')
Out[23]:
    0
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN

PS NumPy / Pandas / SciPy / etc. have their own representation of Vanilla Python None- NaN(Not A Number) or NaT(not time for types similar to DateTime)

+2
source

Source: https://habr.com/ru/post/1665585/


All Articles