将 pandas DataFrame 保存到 feather 时是否可以指定列类型?
is it possible to specify column types when saving a pandas DataFrame to feather?
目前,如果一列碰巧只有空值,则会抛出异常并显示错误:
Invalid: Unable to infer type of object array, were all null
是否可以指定将使用的列类型而不是推断类型?
版本:
feather-format==0.3.1
pandas==0.19.1
示例代码:
feather.write_dataframe(pandas.DataFrame([None]*5), '/tmp/test.feather')
将 None
更改(或替换)为 numpy.nan
,它将起作用:
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 / 等有自己的 Vanilla Python 的 None
- NaN
表示(不是数字)或 NaT
(不是类似 DateTime 数据类型的时间)
目前,如果一列碰巧只有空值,则会抛出异常并显示错误:
Invalid: Unable to infer type of object array, were all null
是否可以指定将使用的列类型而不是推断类型?
版本:
feather-format==0.3.1
pandas==0.19.1
示例代码:
feather.write_dataframe(pandas.DataFrame([None]*5), '/tmp/test.feather')
将 None
更改(或替换)为 numpy.nan
,它将起作用:
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 / 等有自己的 Vanilla Python 的 None
- NaN
表示(不是数字)或 NaT
(不是类似 DateTime 数据类型的时间)