Skip to content

Commit

Permalink
DOC: Sphinx docs creating Series with list of arrays as index to auto…
Browse files Browse the repository at this point in the history
…matically create MultiIndex #831
  • Loading branch information
Chang She committed May 7, 2012
1 parent bc02347 commit b60cf46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions doc/source/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit b60cf46

Please sign in to comment.