Skip to content

DOC: add documentation to IndexSlice #15623

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

Merged
merged 8 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ MultiIndex
:toctree: generated/

MultiIndex
IndexSlice

MultiIndex Components
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
32 changes: 31 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,37 @@ def get_indexers_list():

# the public IndexSlicerMaker
class _IndexSlice(object):

"""
Create an object to more easily perform multi-index slicing

Examples
--------

>>> miindex = pd.MultiIndex.from_product([['A0','A1'],['B0','B1','B2','B3']])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long. But you can rename the miindex to eg midx, then it should fit :-)

>>> columns = ['foo','bar']
>>> dfmi = pd.DataFrame(np.arange(16).reshape((len(miindex),len(columns))),
index=miindex,columns=columns)

Using the default slice command:

>>> dfmi.loc[(slice(None),slice('B0','B1')),:]
foo bar
A0 B0 0 1
B1 2 3
A1 B0 8 9
B1 10 11

Using the IndexSlice class for a more intuitive command:

>>> idx = pd.IndexSlice
>>> dfmi.loc[idx[:,['B0','B1']],:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fully equivalent to the one above, the ['B0','B1'] should be 'B0':'B1' I think

foo bar
A0 B0 0 1
B1 2 3
A1 B0 8 9
B1 10 11
"""

def __getitem__(self, arg):
return arg

Expand Down