2014-11-04 74 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數據。