Skip to content

read_csv with usecols and implicit index columns #5055

Closed
@JamesRamm

Description

@JamesRamm

Pandas 0.12
When specifying usecols with read_csv it seems impossible to use an implicit (no header) index column

Example:

>>> data = 'a,b,c\n4,apple,bat,5.7\n8,orange,cow,10'
>>> pd.read_csv(StringIO(data))
        a    b     c
4   apple  bat   5.7
8  orange  cow  10.0
>>> pd.read_csv(StringIO(data), usecols=['a', 'b'])
        a    b     
0   apple  bat
1  orange  cow
>>>

Where you would prefer/expect this:

>>> pd.read_csv(StringIO(data), usecols=['a', 'b'])
        a    b     
4   apple  bat
8  orange  cow

Specifying index_col = 0 would give:

>>> pd.read_csv(StringIO(data), usecols=['a', 'b'], index_col = 0)
          b     
apple   bat
orange  cow

So this would only work if we explicity pass the column to be used as an index to usecols. However, we cannot explicitly pass an implicit index column to usecols as the index column is not named (it has no header).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions