Skip to content

DOC: expand the documentation on the xs method #4921

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 1 commit into from
Sep 22, 2013
Merged
Changes from all 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
35 changes: 35 additions & 0 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,41 @@ selecting data at a particular level of a MultiIndex easier.

df.xs('one', level='second')

You can also select on the columns with :meth:`~pandas.MultiIndex.xs`, by
providing the axis argument

.. ipython:: python

df = df.T
df.xs('one', level='second', axis=1)

:meth:`~pandas.MultiIndex.xs` also allows selection with multiple keys

.. ipython:: python

df.xs(('one', 'bar'), level=('second', 'first'), axis=1)


.. versionadded:: 0.13.0

You can pass ``drop_level=False`` to :meth:`~pandas.MultiIndex.xs` to retain
the level that was selected

.. ipython::

df.xs('one', level='second', axis=1, drop_level=False)

versus the result with ``drop_level=True`` (the default value)

.. ipython::

df.xs('one', level='second', axis=1, drop_level=True)

.. ipython::
:suppress:

df = df.T

.. _indexing.advanced_reindex:

Advanced reindexing and alignment with hierarchical index
Expand Down