Skip to content

Commit 65c0441

Browse files
kimsey0TomAugspurger
authored andcommitted
DOC: Update documentation of read_csv (#25502)
* Update documentation of read_csv to explain that index_col can be a string containg a column name.
1 parent 01d3dc2 commit 65c0441

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

doc/source/user_guide/io.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ names : array-like, default ``None``
110110
List of column names to use. If file contains no header row, then you should
111111
explicitly pass ``header=None``. Duplicates in this list will cause
112112
a ``UserWarning`` to be issued.
113-
index_col : int or sequence or ``False``, default ``None``
114-
Column to use as the row labels of the ``DataFrame``. If a sequence is given, a
115-
MultiIndex is used. If you have a malformed file with delimiters at the end of
116-
each line, you might consider ``index_col=False`` to force pandas to *not* use
117-
the first column as the index (row names).
113+
index_col : int, str, sequence of int / str, or False, default ``None``
114+
Column(s) to use as the row labels of the ``DataFrame``, either given as
115+
string name or column index. If a sequence of int / str is given, a
116+
MultiIndex is used.
117+
118+
Note: ``index_col=False`` can be used to force pandas to *not* use the first
119+
column as the index, e.g. when you have a malformed file with delimiters at
120+
the end of each line.
118121
usecols : list-like or callable, default ``None``
119122
Return a subset of the columns. If list-like, all elements must either
120123
be positional (i.e. integer indices into the document columns) or strings

pandas/io/parsers.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@
102102
List of column names to use. If file contains no header row, then you
103103
should explicitly pass ``header=None``. Duplicates in this list will cause
104104
a ``UserWarning`` to be issued.
105-
index_col : int, sequence or bool, optional
106-
Column to use as the row labels of the DataFrame. If a sequence is given, a
107-
MultiIndex is used. If you have a malformed file with delimiters at the end
108-
of each line, you might consider ``index_col=False`` to force pandas to
109-
not use the first column as the index (row names).
105+
index_col : int, str, sequence of int / str, or False, default ``None``
106+
Column(s) to use as the row labels of the ``DataFrame``, either given as
107+
string name or column index. If a sequence of int / str is given, a
108+
MultiIndex is used.
109+
110+
Note: ``index_col=False`` can be used to force pandas to *not* use the first
111+
column as the index, e.g. when you have a malformed file with delimiters at
112+
the end of each line.
110113
usecols : list-like or callable, optional
111114
Return a subset of the columns. If list-like, all elements must either
112115
be positional (i.e. integer indices into the document columns) or strings

0 commit comments

Comments
 (0)