在 0.11(本周即将推出)中,这是一种合理的方法
In [50]: arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
.....: np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]
In [51]: df = pd.DataFrame(np.random.randn(8, 4), index=arrays)
In [52]: df
Out[52]:
0 1 2 3
bar one -1.798562 0.852583 -0.148094 -2.107990
two -1.091486 -0.748130 0.519758 2.621751
baz one -1.257548 0.210936 -0.338363 -0.141486
two -0.810674 0.323798 -0.030920 -0.510224
foo one -0.427309 0.933469 -1.259559 -0.771702
two -2.060524 0.795388 -1.458060 -1.762406
qux one -0.574841 0.023691 -1.567137 0.462715
two 0.936323 0.346049 -0.709112 0.045066
In [53]: df.loc['qux'].iloc[[-1]]
Out[53]:
0 1 2 3
two 0.936323 0.346049 -0.709112 0.045066
这将适用于 0.10.1
In [63]: df.ix['qux'].ix[-1]
Out[63]:
0 0.936323
1 0.346049
2 -0.709112
3 0.045066
Name: two, dtype: float64
还有另一种方式(这适用于 0.10.1)以及
In [59]: df.xs(('qux','two'))
Out[59]:
0 0.936323
1 0.346049
2 -0.709112
3 0.045066
Name: (qux, two), dtype: float64