Skip to content

Commit f137bd0

Browse files
author
eric
committed
Encase usecols in double back ticks for consistency. Change column names from numeric to string.
1 parent d2bd6c3 commit f137bd0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

doc/source/io.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ usecols : array-like or callable, default ``None``
136136
that correspond to column names provided either by the user in `names` or
137137
inferred from the document header row(s). For example, a valid array-like
138138
`usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``.
139-
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. Element
140-
order is ignored, so usecols=[1,0] is the same as [0,1]. To instantiate a
141-
DataFrame with element order preserved use ``pd.read_csv(usecols=[0, 1])[[0, 1]]``
142-
for columns in ``[1, 0]`` order or ``pd.read_csv(usecols=[0, 1])[[0, 1]]``
143-
for ``[0, 1]`` order.
139+
Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. To
140+
instantiate a DataFrame from ``data`` with element order preserved use
141+
``pd.read_csv(data, usecols=['foo', 'bar'])[['foo', 'bar']]`` for columns
142+
in ``['foo', 'bar']`` order or
143+
``pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]`` for
144+
``['bar', 'foo']`` order.
144145

145146
If callable, the callable function will be evaluated against the column names,
146147
returning names where the callable function evaluates to True:

pandas/io/parsers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@
102102
that correspond to column names provided either by the user in `names` or
103103
inferred from the document header row(s). For example, a valid array-like
104104
`usecols` parameter would be [0, 1, 2] or ['foo', 'bar', 'baz']. Element
105-
order is ignored, so usecols=[1,0] is the same as [0,1]. To instantiate a
106-
DataFrame with element order preserved use
107-
``pd.read_csv(usecols=[0, 1])[[0, 1]]`` for columns in ``[1, 0]``
108-
order or ``pd.read_csv(usecols=[0, 1])[[0, 1]]`` for ``[0, 1]`` order.
105+
order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``.
106+
To instantiate a DataFrame from ``data`` with element order preserved use
107+
``pd.read_csv(data, usecols=['foo', 'bar'])[['foo', 'bar']]`` for columns
108+
in ``['foo', 'bar']`` order or
109+
``pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]``
110+
for ``['bar', 'foo']`` order.
109111
110112
If callable, the callable function will be evaluated against the column
111113
names, returning names where the callable function evaluates to True. An

0 commit comments

Comments
 (0)