2014-11-04 71 views
2

我在理解pandas.Panel(3D数据结构)的索引时遇到了一些麻烦。在documentation中指出,分度工作方式:索引pandas.Panel违反直觉或错误?

获取值从物体与多轴选择使用如下标记(使用的.loc作为一个例子,但适用于.iloc和.IX以及)。任何轴访问器都可能是空片:。被忽略的轴被假定为:。 (egploc [ 'A']是当量至p.loc [ '一个',:,:])

p.loc [item_indexer,major_indexer,minor_indexer]

现在我将认为其余指数的订单时,被提取的数据帧不改变,而是:

from pandas import Panel 
from numpy import arange 
p = Panel(arange(24).reshape(2,3,4)) 
p.shape 
Out[4]: (2, 3, 4) 
p.iloc[0].shape # original order 
Out[5]: (3, 4) 
p.iloc[:,0].shape # transposed 
Out[6]: (4, 2) 
p.iloc[:,:,0].shape # transposed 
Out[7]: (3, 2) 
p.iloc[:,0,:].shape # transpose (same as [6]) 
Out[8]: (4, 2) 
p.iloc[1:,0,:].shape # Slicing item_indexer, then transpose 
Out[9]: (4, 1) 
p.iloc[1:,0].shape # Expected to get the same as [9], but slicing minor_indexer instead???? 
Out[10]: (3, 2) 

为什么索引major_index或minor_index,但不是item_index当数据帧调换任何想法?为什么最后一个例子与之前的例子不同?

Link to github issue

+0

我想没有人知道... – Rob 2015-07-24 09:56:36

回答

1

近来一直在github issue一些讨论。似乎熊猫对N维数据的适应性不好(N> = 3)。有一个替代模块xray,这是像熊猫,但ND数据。否则,您可以使用带有MultiIndex的普通熊猫(2D)DataFrames来模拟ND数据。