如何在 pandas HDStore(pyTables)中访问索引 [英] how to access index in a pandas HDStore (pyTables)
本文介绍了如何在 pandas HDStore(pyTables)中访问索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有多索引的大型HDFStore.如何获得其中一个指数水平?我看到我可以像这样访问colindex:
I have a large HDFStore with a multi-index. How can I get a hold of one of the index levels? I see I can access the colindex like so:
store._handle.root.data.table.colindexes
但尚未获得列索引之一的列表.
But have yet to get a list of one of the column indexes.
推荐答案
以表格格式存储(请注意,在0.13中,您将传递format='table'
)
Store in table format (note that in 0.13 you will pass format='table'
)
In [24]: df_mi.to_hdf('test.h5','df_mi',table=True,mode='w')
检索单个列. MI被存储为列!
To retrieve a single column. The MI are stored as columns!
In [25]: store = pd.HDFStore('test.h5')
In [26]: store.select_column('df_mi','foo')
Out[26]:
0 foo
1 foo
2 foo
3 bar
4 bar
5 baz
6 baz
7 qux
8 qux
9 qux
dtype: object
In [30]: store.select_column('df_mi','bar')
Out[30]:
0 one
1 two
2 three
3 one
4 two
5 two
6 three
7 one
8 two
9 three
dtype: object
In [31]: store.close()
这篇关于如何在 pandas HDStore(pyTables)中访问索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文