From b60cf46f679a525aa60e4e0e919805319f600346 Mon Sep 17 00:00:00 2001 From: Chang She Date: Mon, 7 May 2012 16:38:28 -0400 Subject: [PATCH] DOC: Sphinx docs creating Series with list of arrays as index to automatically create MultiIndex #831 --- doc/source/dsintro.rst | 3 ++- doc/source/indexing.rst | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst index 83a8feee8109d..23f603a820bee 100644 --- a/doc/source/dsintro.rst +++ b/doc/source/dsintro.rst @@ -70,7 +70,8 @@ index is passed, one will be created having values ``[0, ..., len(data) - 1]``. .. note:: - The values in the index must be unique. If they are not, an exception will + Starting in v0.8.0, pandas supports non-unique index values. In previous + version, if the index values are not unique an exception will **not** be raised immediately, but attempting any operation involving the index will later result in an exception. In other words, the Index object containing the labels "lazily" checks whether the values are unique. The diff --git a/doc/source/indexing.rst b/doc/source/indexing.rst index 82023cf5fc9a5..4f8c7166e5024 100644 --- a/doc/source/indexing.rst +++ b/doc/source/indexing.rst @@ -607,6 +607,17 @@ can think of ``MultiIndex`` an array of tuples where each tuple is unique. A s = Series(randn(8), index=index) s +As a convenience, you can pass a list of arrays directly into Series or +DataFrame to construct a MultiIndex automatically: + +.. ipython:: python + arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']), + np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])] + s = Series(randn(8), index=arrays) + s + df = DataFrame(randn(8, 4), index=arrays) + df + All of the ``MultiIndex`` constructors accept a ``names`` argument which stores string names for the levels themselves. If no names are provided, some arbitrary ones will be assigned: @@ -641,6 +652,7 @@ can find yourself working with hierarchically-indexed data without creating a ``MultiIndex`` explicitly yourself. However, when loading data from a file, you may wish to generate your own ``MultiIndex`` when preparing the data set. + Reconstructing the level labels ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~