Skip to content

read_csv with usecols and implicit index columns #5055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JamesRamm opened this issue Sep 30, 2013 · 4 comments
Closed

read_csv with usecols and implicit index columns #5055

JamesRamm opened this issue Sep 30, 2013 · 4 comments

Comments

@JamesRamm
Copy link

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).

@jtratner
Copy link
Contributor

Are you sure you're using current master? Here's what I get for your example:

In [2]: data = 'a,b,c\n4,apple,bat,5.7\n8,orange,cow,10'

In [3]: from StringIO import StringIO

In [4]: pd.read_csv(StringIO(data))
Out[4]:
        a    b     c
4   apple  bat   5.7
8  orange  cow  10.0

In [5]: pd.read_csv(StringIO(data), usecols=['a', 'b'])
Out[5]:
        a    b
4   apple  bat
8  orange  cow
In [6]: pd.__version__
Out[6]: '0.12.0-625-g3e47a3b'

@jreback
Copy link
Contributor

jreback commented Sep 30, 2013

this was closed recently via : #5003

I believe op is using 0.12, which was buggy

@jreback jreback closed this as completed Sep 30, 2013
@JamesRamm
Copy link
Author

I'm using version 0.12.0 - this not the most recent?

@jreback
Copy link
Contributor

jreback commented Oct 1, 2013

it is the most recent release version. 0.13 several weeks away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants