在PyTables表中存储pandas DataFrame而不存储索引

1 投票
2 回答
746 浏览
提问于 2025-04-18 18:39

在很多 DataFrame.to_foo 函数中,我可以指定不想写入索引。

>>> help(df.to_csv)

Write DataFrame to a comma-separated values (csv) file

Parameters
----------
...
index : boolean, default True
    Write row names (index)
...

那么,DataFrame.to_hdf 也有类似的功能吗?我希望在 PyTables 表中不存储索引。

2 个回答

0

在Pandas中,抑制索引并不是一个开箱即用的功能。这个问题正在被关注,具体情况可以在这里查看:

https://github.com/pydata/pandas/issues/8319

1

你可以使用h5py这个库,直接和HDF5文件进行交互。

data = df.values
with h5py.File('data.h5','w') as f:
    f.create_dataset('my_table', data=data)

撰写回答