Skip to content

read_csv skips rows with value 0 if having initial space #9710

Closed
@aarimond

Description

@aarimond

Hi,

I have something like the following csv file:

MyColumn
   0
   1
   0
   1

Note the initial space in each row.
Upgrading from 0.14.1 to 0.16 I recognized that read_csv started throwing away the 0 rows

In [28]: import pandas
In [29]: from StringIO import StringIO
In [30]: data = 'MyColumn\n   0\n   1\n   0\n   1'
In [31]: pandas.read_csv(StringIO(data))
Out[31]:
   MyColumn
0         1
1         1

skipinitialspace=True did not help:

In [32]: pandas.read_csv(StringIO(data), skipinitialspace=True)
Out[32]:
   MyColumn
0         1
1         1

however, skip_blank_lines=False would help:

In [34]: pandas.read_csv(StringIO(data), skip_blank_lines=False)
Out[34]:
   MyColumn
0         0
1         1
2         0
3         1

Not sure if this is working as intended.

Cheers,
Alex

PS:
Having a second columns works as expected:

In [40]: data = 'MyColumn,SecondColumn\n   0, 2\n   1, 3\n   0, 0\n   1, 4'
In [41]: pandas.read_csv(StringIO(data))
Out[41]:
   MyColumn  SecondColumn
0         0             3
1         1             4
2         0             0
3         1             6

UPDATE:
Made code more reproducable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions