You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [476]: df1
Out[476]:
cnt
a1 a2
a abcde 1
b bbcde 2
y yzcde 25
z xbcde 24
NaN 26
zbcde 25
ybcde 26
[7 rows x 1 columns]
In [477]: df1.xs('z',level='a1')
Out[477]:
cnt
a2
xbcde 24
zbcde 26
zbcde 25
ybcde 26
[4 rows x 1 columns]
I was expecting:
cnt
a2
xbcde 24
NaN 26
zbcde 25
ybcde 26
because I thought it would preserve the index of df1.
Sorting explicitly doesn't seem to affect the result:
In [478]: df1.sort('cnt',ascending=False)
Out[478]:
cnt
a1 a2
z ybcde 26
NaN 26
zbcde 25
y yzcde 25
z xbcde 24
b bbcde 2
a abcde 1
[7 rows x 1 columns]
In [479]: df1.sort('cnt',ascending=False).xs('z',level='a1')
Out[479]:
cnt
a2
ybcde 26
zbcde 26
zbcde 25
xbcde 24
[4 rows x 1 columns]
It might be related to forward filling, but then I think it would be:
Here's some other ways to get at what you want
(this may be a bug, as having NaN in an index is in general odd, so maybe some code
to 'deal' with that)
In [3]: df1.xs('z',level='a1',drop_level=False)
Out[3]:
cnt
a1 a2
z xbcde 24
NaN 26
zbcde 25
ybcde 26
[4 rows x 1 columns]
In [4]: df1.loc[['z']]
Out[4]:
cnt
a1 a2
z xbcde 24
NaN 26
zbcde 25
ybcde 26
[4 rows x 1 columns]
In [5]: df1.loc['z']
Out[5]:
cnt
a2
xbcde 24
zbcde 26
zbcde 25
ybcde 26
[4 rows x 1 columns]
Illustration:
I was expecting:
because I thought it would preserve the index of df1.
Sorting explicitly doesn't seem to affect the result:
It might be related to forward filling, but then I think it would be:
which still isn't what I was expecting.
Versions and dependencies:
The text was updated successfully, but these errors were encountered: