HDF5 格式显然不支持 format="fixed"的分类。下面的例子
s = pd.Series(['a','b','a','b'],dtype='category')
s.to_hdf('s.h5','s')
返回错误:
NotImplementedError: Cannot store a category dtype in a HDF5 dataset that uses format="fixed". Use format="table".
如何使用 format='table' 构造分类系列?
最佳答案
在pd.Series.to_hdf
中指定format='table'
或format='t'
:
s.to_hdf('s.h5', key='s', format='t')
请注意,这也是错误消息所建议的。根据 the docs :
format : ‘fixed(f)|table(t)’, default is ‘fixed’
fixed(f) : Fixed format Fast writing/reading. Not-appendable, nor searchable
table(t) : Table format Write as a PyTables Table structure which may perform worse but allow more flexible operations like searching / selecting subsets of the data
关于python - 在 Pandas 分类中,格式 ="table"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165398/