<p>您可以使用列的索引存储dataframe,如下所示:</p>
<pre><code>import pandas as pd
import numpy as np
from pandas.io.pytables import Term
index = pd.date_range('1/1/2000', periods=8)
df = pd.DataFrame( np.random.randn(8,3), index=index, columns=list('ABC'))
store = pd.HDFStore('mydata.h5')
store.append('df_cols', df, axes='columns')
</code></pre>
<p>然后根据您的希望选择:</p>
<pre><code>In [8]: store.select('df_cols', [Term('columns', '=', 'A')])
Out[8]:
2000-01-01 0.347644
2000-01-02 0.477167
2000-01-03 1.419741
2000-01-04 0.641400
2000-01-05 -1.313405
2000-01-06 -0.137357
2000-01-07 -1.208429
2000-01-08 -0.539854
</code></pre>
<p>其中:</p>
<pre><code>In [9]: df
Out[9]:
A B C
2000-01-01 0.347644 0.895084 -1.457772
2000-01-02 0.477167 0.464013 -1.974695
2000-01-03 1.419741 0.470735 -0.309796
2000-01-04 0.641400 0.838864 -0.112582
2000-01-05 -1.313405 -0.678250 -0.306318
2000-01-06 -0.137357 -0.723145 0.982987
2000-01-07 -1.208429 -0.672240 1.331291
2000-01-08 -0.539854 -0.184864 -1.056217
</code></pre>
<p>是的。</p>
<p>对我来说,这不是一个理想的解决方案,因为我们只能通过一件事来索引数据帧!令人担忧的是,<a href="http://pandas.pydata.org/pandas-docs/dev/io.html#hdf5-pytables" rel="noreferrer">the docs</a>似乎建议您<em>可以</em>只通过一件事索引一个数据帧,至少使用<code>axes</code>:</p>
<blockquote>
<p>Pass the axes keyword with a list of dimension (currently must by exactly 1 less than the total dimensions of the object).</p>
</blockquote>
<p>我可能读错了,希望有人能证明我错了!</strong></p>
<p>是的。</p>
<p>注意:我发现用两种方法(索引和列)索引数据帧的一种方法是将其转换为一个面板,然后面板可以使用两个索引进行检索。但是,每次检索项目时,我们都必须将选定的子面板转换为数据帧。。。再说一次,不太理想。</p>