Skip to content

ENH: Allow list of keys in Dataframe.xs for each level #20397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
harisbal opened this issue Mar 18, 2018 · 3 comments
Closed

ENH: Allow list of keys in Dataframe.xs for each level #20397

harisbal opened this issue Mar 18, 2018 · 3 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Usage Question

Comments

@harisbal
Copy link
Contributor

arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
            np.array(['one', 'two', 'three', 'two', 'one', 'two', 'one', 'two'])]

df = pd.DataFrame(np.random.randn(8, 4), index=arrays)

It would probably be nice to allow for

df.xs([['bar', 'baz'], ['one', 'three']], level=[0,1])

@jreback
Copy link
Contributor

jreback commented Mar 18, 2018

you can already do this with slicers (and has been this way for a while) dohttp://pandas.pydata.org/pandas-docs/stable/advanced.html#using-slicers

likeley to deprecate .xs anyhow.

In [3]: ix = pd.IndexSlice

In [4]: df.loc[ix[['bar', 'baz'], ['one', 'three']], :]
Out[4]: 
                  0         1         2         3
bar one    3.019096  0.096874 -0.832045  1.413082
baz three  1.357525  0.124628  0.116054  1.759177

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Mar 18, 2018
@jreback jreback added this to the No action milestone Mar 18, 2018
@jreback
Copy link
Contributor

jreback commented Mar 18, 2018

related issue is: #4036

certainly welcome help on these!

@harisbal
Copy link
Contributor Author

I like the drop level parameter of xs and that's the main reason I use it. I realised though that passing lists could make impossible to drop the filtered levels and that why I closed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants