Skip to content

Commit

Permalink
DOC: documented reading CSV/table into MultiIndex, address GH #165
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Sep 25, 2011
1 parent cdab269 commit 8351bf5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/data/mindex_ex.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
year,indiv,zit,xit
1977,"A",1.2,.6
1977,"B",1.5,.5
1977,"C",1.7,.8
1978,"A",.2,.06
1978,"B",.7,.2
1978,"C",.8,.3
1978,"D",.9,.5
1978,"E",1.4,.9
1979,"C",.2,.15
1979,"D",.14,.05
1979,"E",.5,.15
1979,"F",1.2,.5
1979,"G",3.4,1.9
1979,"H",5.4,2.7
1979,"I",6.4,1.2
18 changes: 18 additions & 0 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ fragile. Type inference is a pretty big deal. So if a column can be coerced to
integer dtype without altering the contents, it will do so. Any non-numeric
columns will come through as object dtype as with the rest of pandas objects.

Reading DataFrame objects with ``MultiIndex``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Suppose you have data indexed by two columns:

.. ipython:: python
print open('data/mindex_ex.csv').read()
The ``index_col`` argument to ``read_csv`` and ``read_table`` can take a list of
column numbers to turn multiple columns into a ``MultiIndex``:

.. ipython:: python
df = read_csv("data/mindex_ex.csv", index_col=[0,1])
df
df.ix[1978]
Excel 2003 files
----------------

Expand Down

0 comments on commit 8351bf5

Please sign in to comment.