@@ -115,10 +115,10 @@ They can take a number of arguments:
115
115
- ``error_bad_lines ``: if False then any lines causing an error will be skipped :ref: `bad lines <io.bad_lines >`
116
116
- ``usecols ``: a subset of columns to return, results in much faster parsing
117
117
time and lower memory usage.
118
- - ``mangle_dup_columns ``: boolean, default True, then duplicate columns will be specified
118
+ - ``mangle_dupe_cols ``: boolean, default True, then duplicate columns will be specified
119
119
as 'X.0'...'X.N', rather than 'X'...'X'
120
- - ``multi_index_columns_compat ``: boolean, default False, leave a list of tuples on columns
121
- as is (default is to convert to a Multi Index on the columns)
120
+ - ``tupleize_cols ``: boolean, default True, if False, convert a list of tuples
121
+ to a multi-index of columns, otherwise, leave the column index as a list of tuples
122
122
123
123
.. ipython :: python
124
124
:suppress:
@@ -260,24 +260,6 @@ If the header is in a row other than the first, pass the row number to
260
260
data = ' skip this skip it\n a,b,c\n 1,2,3\n 4,5,6\n 7,8,9'
261
261
pd.read_csv(StringIO(data), header = 1 )
262
262
263
- .. _io.multi_index_columns :
264
-
265
- Specifying a multi-index columns
266
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
-
268
- By specifying list of row locations for the ``header `` argument, you
269
- can read in a multi-index for the columns. Specifying non-consecutive
270
- rows will skip the interveaing rows. The ``index_col `` must also be
271
- specified.
272
-
273
- .. ipython :: python
274
-
275
- data = ' C0,C_l0_g0,C_l0_g1\n C1,C_l1_g0,C_l1_g1\n R0,,\n R_l0_g0,R0C0,R0C1\n R_l0_g1,R1C0,R1C1\n R_l0_g2,R2C0,R2C1\n '
276
- pd.read_csv(StringIO(data), header = [0 ,1 ], index_col = [0 ])
277
-
278
- You can pass ``multi_index_columns_compat=True `` to preserve the pre-0.12 behavior of
279
- not converting a list of tuples in the columns to a Multi Index.
280
-
281
263
.. _io.usecols :
282
264
283
265
Filtering columns (``usecols ``)
@@ -787,6 +769,36 @@ column numbers to turn multiple columns into a ``MultiIndex``:
787
769
df
788
770
df.ix[1978 ]
789
771
772
+ .. _io.multi_index_columns :
773
+
774
+ Specifying a multi-index columns
775
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
776
+
777
+ By specifying list of row locations for the ``header `` argument, you
778
+ can read in a multi-index for the columns. Specifying non-consecutive
779
+ rows will skip the interveaing rows.
780
+
781
+ .. ipython :: python
782
+
783
+ from pandas.util.testing import makeCustomDataframe as mkdf
784
+ df = mkdf(5 ,3 ,r_idx_nlevels = 2 ,c_idx_nlevels = 4 )
785
+ df.to_csv(' mi.csv' ,tupleize_cols = False )
786
+ print open (' mi.csv' ).read()
787
+ pd.read_csv(' mi.csv' ,header = [0 ,1 ,2 ,3 ],index_col = [0 ,1 ],tupleize_cols = False )
788
+
789
+ Note: The default behavior in 0.11.1 remains unchanged (``tupleize_cols=True ``),
790
+ but starting with 0.12, the default *to * write and read multi-index columns will be in the new
791
+ format (``tupleize_cols=False ``)
792
+
793
+ Note: If an ``index_col `` is not specified (e.g. you don't have an index, or wrote it
794
+ with ``df.to_csv(..., index=False ``), then any ``names `` on the columns index will be *lost *.
795
+
796
+ .. ipython :: python
797
+ :suppress:
798
+
799
+ import os
800
+ os.remove(' mi.csv' )
801
+
790
802
.. _io.sniff :
791
803
792
804
Automatically "sniffing" the delimiter
@@ -870,6 +882,8 @@ function takes a number of arguments. Only the first is required.
870
882
- ``sep `` : Field delimiter for the output file (default ",")
871
883
- ``encoding ``: a string representing the encoding to use if the contents are
872
884
non-ascii, for python versions prior to 3
885
+ - ``tupleize_cols ``: boolean, default True, if False, write as a list of tuples,
886
+ otherwise write in an expanded line format suitable for ``read_csv ``
873
887
874
888
Writing a formatted string
875
889
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -901,6 +915,9 @@ The Series object also has a ``to_string`` method, but with only the ``buf``,
901
915
which, if set to ``True ``, will additionally output the length of the Series.
902
916
903
917
918
+ HTML
919
+ ----
920
+
904
921
Reading HTML format
905
922
~~~~~~~~~~~~~~~~~~~~~~
906
923
0 commit comments