Skip to content

read_csv: usecols doesn't work if separator is not "," #2733

Closed
@bmu

Description

@bmu

If I have data (without a header) separated by "," usecols works, however if the data is separated by white space it doesn't seem to work:

In [30]: data = '1,2,3\n4,5,6\n7,8,9'

In [31]: pd.read_csv(StringIO(data), usecols=[0, 1], header=None)
Out[31]: 
   0  1
0  1  2
1  4  5
2  7  8

In [32]: data = '1 2 3\n4 5 6\n7 8 9'

In [33]: pd.read_csv(StringIO(data), sep='\s+', header=None)
Out[33]: 
   0  1  2
0  1  2  3
1  4  5  6
2  7  8  9

In [34]: pd.read_csv(StringIO(data), sep='\s+', usecols=[0, 1], header=None)
Out[34]: 
   0  1  2
0  1  2  3
1  4  5  6
2  7  8  9

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugEnhancementIO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions