From a796a37d73fb7fb9da0ae61d7927c669e63cf8f2 Mon Sep 17 00:00:00 2001 From: tp Date: Sun, 24 Sep 2017 01:52:26 +0200 Subject: [PATCH 1/2] Added example to MultiIndex doc string --- pandas/core/indexes/multi.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 0b7c5f414b178..8a5ea8a10cb38 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -68,6 +68,33 @@ class MultiIndex(Index): Copy the meta-data verify_integrity : boolean, default True Check that the levels/labels are consistent and valid + + Examples + --------- + A new ``MultiIndex`` is typically constructed using one of the helper + methods :meth:`MultiIndex.from_arrays``, :meth:`MultiIndex.from_product`` + and :meth:`MultiIndex.from_tuples``. For example (using ``.from_arrays``): + + >>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']] + >>> MultiIndex.from_arrays(arrays, names=('number', 'color')) + MultiIndex(levels=[[1, 2], ['blue', 'red']], + labels=[[0, 0, 1, 1], [1, 0, 1, 0]], + names=['number', 'color']) + + See further examples for how to construct a MultiIndex in the doc strings + of the mentioned helper methods. + + Notes + ----- + See the `user guide + `_ for more. + + See Also + -------- + MultiIndex.from_arrays : Convert list of arrays to MultiIndex + MultiIndex.from_product : Create a MultiIndex from the cartesian product + of iterables + MultiIndex.from_tuples : Convert list of tuples to a MultiIndex """ # initialize to zero-length tuples to make everything work From 0daf641f897571ff1fc65b05e7b5cd8665a13f2c Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 25 Sep 2017 10:11:28 +0200 Subject: [PATCH 2/2] add pd. --- pandas/core/indexes/multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 8a5ea8a10cb38..8c6b26c9070a9 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -76,7 +76,7 @@ class MultiIndex(Index): and :meth:`MultiIndex.from_tuples``. For example (using ``.from_arrays``): >>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']] - >>> MultiIndex.from_arrays(arrays, names=('number', 'color')) + >>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color')) MultiIndex(levels=[[1, 2], ['blue', 'red']], labels=[[0, 0, 1, 1], [1, 0, 1, 0]], names=['number', 'color'])