Skip to content

Commit f803199

Browse files
author
Felix Lawrence
committed
DOC: Clarified documentation for MultiIndexes
Add examples and rewrite an awkwardly-written bit Cross-reference MultiIndex constructors
1 parent 0f2a7d2 commit f803199

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

doc/source/indexing.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,10 @@ completely analogous way to selecting a column in a regular DataFrame:
16381638
df['bar']['one']
16391639
s['qux']
16401640
1641+
See :ref:`Cross-section with hierarchical index <indexing.xs>` for how to select
1642+
on a deeper level.
1643+
1644+
16411645
Data alignment and using ``reindex``
16421646
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16431647

@@ -1674,11 +1678,17 @@ following works as you would expect:
16741678
df.ix['bar']
16751679
df.ix['bar', 'two']
16761680
1677-
"Partial" slicing also works quite nicely:
1681+
"Partial" slicing also works quite nicely for the topmost level:
16781682

16791683
.. ipython:: python
16801684
16811685
df.ix['baz':'foo']
1686+
1687+
But lower levels cannot be sliced in this way, because the MultiIndex uses
1688+
its multiple index dimensions to slice along one dimension of your object:
1689+
1690+
.. ipython:: python
1691+
16821692
df.ix[('baz', 'two'):('qux', 'one')]
16831693
df.ix[('baz', 'two'):'foo']
16841694

pandas/core/index.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -2472,14 +2472,25 @@ def from_arrays(cls, arrays, sortorder=None, names=None):
24722472
24732473
Parameters
24742474
----------
2475-
arrays : list / sequence
2475+
arrays : list / sequence of array-likes
2476+
Each array-like gives one level's value for each data point.
2477+
len(arrays) is the number of levels.
24762478
sortorder : int or None
24772479
Level of sortedness (must be lexicographically sorted by that
24782480
level)
24792481
24802482
Returns
24812483
-------
24822484
index : MultiIndex
2485+
2486+
Examples
2487+
--------
2488+
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
2489+
>>> MultiIndex.from_arrays(arrays, names=('number', 'color'))
2490+
2491+
See Also
2492+
--------
2493+
MultiIndex.from_tuples : Convert list of tuples to MultiIndex
24832494
"""
24842495
from pandas.core.categorical import Categorical
24852496

@@ -2504,14 +2515,25 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
25042515
25052516
Parameters
25062517
----------
2507-
tuples : array-like
2518+
tuples : list / sequence of tuple-likes
2519+
Each tuple is the index of one row/column.
25082520
sortorder : int or None
25092521
Level of sortedness (must be lexicographically sorted by that
25102522
level)
25112523
25122524
Returns
25132525
-------
25142526
index : MultiIndex
2527+
2528+
Examples
2529+
--------
2530+
>>> tuples = [(1, u'red'), (1, u'blue'),
2531+
(2, u'red'), (2, u'blue')]
2532+
>>> MultiIndex.from_tuples(tuples, names=('number', 'color'))
2533+
2534+
See Also
2535+
--------
2536+
MultiIndex.from_arrays : Convert list of arrays to MultiIndex
25152537
"""
25162538
if len(tuples) == 0:
25172539
# I think this is right? Not quite sure...

0 commit comments

Comments
 (0)