Skip to content

read_csv() interprets index_col="True" as "1" #9798

Closed
@kousu

Description

@kousu

epi.txt

OBS ID PERIOD TMT Y0 AGE COUNT
1 1 1 0 11 31 5
2 1 2 0 11 31 3
3 1 3 0 11 31 3
4 1 4 0 11 31 3
5 2 1 0 11 30 3
6 2 2 0 11 30 5
7 2 3 0 11 30 3
8 2 4 0 11 30 3
9 3 1 0 6 25 2
10 3 2 0 6 25 4
epi = pandas.read_csv("./epi.datn.txt", sep=" ", index_col=True)
print(epi)
    OBS  PERIOD  TMT  Y0  AGE  COUNT
ID                                  
1     1       1    0  11   31      5
1     2       2    0  11   31      3
1     3       3    0  11   31      3
1     4       4    0  11   31      3
2     5       1    0  11   30      3
2     6       2    0  11   30      5
2     7       3    0  11   30      3
2     8       4    0  11   30      3
3     9       1    0   6   25      2
3    10       2    0   6   25      4

I had some code that used False to disable reading indexes from the data, and was expecting True to be the opposite. Instead it read the second column, because True == 1 in python.

I think that True should be explicitly handled, because this behaviour is counterintuitive given that False is meaningful. False is not the same as index_col=0, after all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions