MultiIndex(Z、A)を使用した次のPandasデータフレームがあります。
H1 H2
Z A
0 100 200 0.3112 -0.4197
1 100 201 0.2967 0.4893
2 100 202 0.3084 -0.4873
3 100 203 0.3069 NaN
4 101 203 -0.4956 NaN
Question: How can I select all items with A=203?
I tried df[:,'A']
but it doesn't work. Then I found this in the online documentation so I tried:
df.xs(203,level='A')
but I get:
"TypeError: xs() got an unexpected keyword argument 'level'
"
Also I dont see this parameter in the installed doc(df.xs?
):
"Parameters ---------- key : object Some label contained in the index, or partially in a MultiIndex axis : int, default 0 Axis to retrieve cross-section on copy : boolean, default True Whether to make a copy of the data"
Note:I have the development version.
Edit: I found this thread. They recommend something like:
df.select(lambda x: x[1]==200, axis=0)
I still would like to know what happened with df.xs with the level parameter or what is the recommended way in the current version.