Skip to content

DOC: Clarified documentation for MultiIndexes #5964

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
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,10 @@ completely analogous way to selecting a column in a regular DataFrame:
df['bar']['one']
s['qux']

See :ref:`Cross-section with hierarchical index <indexing.xs>` for how to select
on a deeper level.


Data alignment and using ``reindex``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1674,11 +1678,17 @@ following works as you would expect:
df.ix['bar']
df.ix['bar', 'two']

"Partial" slicing also works quite nicely:
"Partial" slicing also works quite nicely for the topmost level:

.. ipython:: python

df.ix['baz':'foo']

But lower levels cannot be sliced in this way, because the MultiIndex uses
its multiple index dimensions to slice along one dimension of your object:

.. ipython:: python

df.ix[('baz', 'two'):('qux', 'one')]
df.ix[('baz', 'two'):'foo']

Expand Down
26 changes: 24 additions & 2 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,14 +2472,25 @@ def from_arrays(cls, arrays, sortorder=None, names=None):

Parameters
----------
arrays : list / sequence
arrays : list / sequence of array-likes
Each array-like gives one level's value for each data point.
len(arrays) is the number of levels.
sortorder : int or None
Level of sortedness (must be lexicographically sorted by that
level)

Returns
-------
index : MultiIndex

Examples
--------
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
>>> MultiIndex.from_arrays(arrays, names=('number', 'color'))

See Also
--------
MultiIndex.from_tuples : Convert list of tuples to MultiIndex
"""
from pandas.core.categorical import Categorical

Expand All @@ -2504,14 +2515,25 @@ def from_tuples(cls, tuples, sortorder=None, names=None):

Parameters
----------
tuples : array-like
tuples : list / sequence of tuple-likes
Each tuple is the index of one row/column.
sortorder : int or None
Level of sortedness (must be lexicographically sorted by that
level)

Returns
-------
index : MultiIndex

Examples
--------
>>> tuples = [(1, u'red'), (1, u'blue'),
(2, u'red'), (2, u'blue')]
>>> MultiIndex.from_tuples(tuples, names=('number', 'color'))

See Also
--------
MultiIndex.from_arrays : Convert list of arrays to MultiIndex
"""
if len(tuples) == 0:
# I think this is right? Not quite sure...
Expand Down