python - 在 Pandas 分类中,格式 ="table"是什么?

标签 python pandas series hdf5 pytables

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/

相关文章:

python - pandas:索引值数组中的系列值

python - 停止连接 pandas 时间序列图中的点

python - 当名称已在同一模块中定义时,名称未定义错误

python - 从两个查询 django 的输出创建嵌套 json

python - 遍历将来的结果时,如何获取发送给ThreadPoolExecutor的参数?

python - 根据列的多个条件将数据帧拆分为 block

python - 在不同的列中删除无序的重复项

python - ":"的 pandas read_table usecols 错误

python - pandas bool 值系列为 True 的输出

python - 使用 Python Anaconda 包 grib_api 时出现 ImportError