Skip to content

Commit b7bd41d

Browse files
author
tp
committed
Added example to MultiIndex doc string
1 parent d43aba8 commit b7bd41d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/core/indexes/multi.py

+17
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ class MultiIndex(Index):
6868
Copy the meta-data
6969
verify_integrity : boolean, default True
7070
Check that the levels/labels are consistent and valid
71+
72+
Examples
73+
---------
74+
A new ``MultiIndex`` is typically constructed using one of the helper
75+
methods :attr:`MultiIndex.from_arrays``, :attr:`MultiIndex.from_tuples``
76+
and :attr:`MultiIndex.from_product``. For example (using ``.from_arrays``):
77+
78+
>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
79+
>>> mi = MultiIndex.from_arrays(arrays, names=('number', 'color'))
80+
>>> mi
81+
82+
Such a ``MultiIndex`` instance can be used as an index in a Series or
83+
DataFrame, e.g.:
84+
85+
>>> pd.Series([1, 2, 3, 4], index=mi)
86+
87+
See the respective helper method doc-strings for further examples.
7188
"""
7289

7390
# initialize to zero-length tuples to make everything work

0 commit comments

Comments
 (0)