Skip to content

read_csv does not set index name on empty dataframe #10184

Closed
@corr723

Description

@corr723

If foo.csv contains

x,y
1,2

then you get the normal behavior:

>>> df = pd.read_csv('foo.csv', index_col=0)
>>> list(df.columns)
['y']
>>> df.index.name
'x'

but if you remove the data row "1,2" in the CSV the index name gets dropped:

>>> df = pd.read_csv('foo.csv', index_col=0)
>>> list(df.columns)
['y']
>>> df.index.name
None

This means round-tripping with to_csv/read_csv fails for empty dataframes.

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