2016-10-12 5 views

答えて

1

pd.Panelオブジェクトがidxmaxメソッドを持っていないpd.Panelp

dfs = dict(
    one=pd.DataFrame(np.random.randint(1, 10, (5, 5))), 
    two=pd.DataFrame(np.random.randint(1, 10, (5, 5))), 
    three=pd.DataFrame(np.random.randint(1, 10, (5, 5))), 
) 

p = pd.Panel(dfs) 
p.to_frame().unstack() 

enter image description here


を検討してください。しかし、基本的な配列はargmaxメソッドを持っています。私はそれを活用するためにこのカスタム関数を構築しました。

def idxmax(pn, axis=0): 
    indices = pd.Series(['items', 'major_axis', 'minor_axis']) 
    idx, col = indices.drop(axis) 
    return pd.DataFrame(pn.values.argmax(axis), 
         pn.__getattribute__(idx), 
         pn.__getattribute__(col)) 

使用

idxmax(p, 0) 

enter image description here

idxmax(p, 1) 

enter image description here

idxmax(p, 2) 

enter image description here

+0

よくできています。ありがとう、トン。アイテム#をアイテム名に置き換えようとすると、あなたはdictでその名前に戻るでしょうか? – MJS

+0

@MJSのようなもの、はい。 – piRSquared

関連する問題