Skip to content

pandas/to-csv-index

Pack Severity Fix Versions
pandas warning unsafe, with xpd check --fix --unsafe-fixes All versions

to_csv writes the index as a first column, which read_csv reads back as Unnamed: 0. Pass index=False, or index=True when the index holds data.

df.to_csv(path)
df.to_csv(path, index=False)

The rule reports df.to_csv(path) without index=, which writes the index as an extra column without a name, or under its name when the index has one. The rule leaves alone a call with no argument and a call that forwards **options.

xpd check --fix --unsafe-fixes adds index=False to to_csv(...) calls that omit index=. It is unsafe because you should pass index=True instead when the index holds meaningful data.

to_csv writes the index as a first column, and when the index has no name read_csv returns it as "Unnamed: 0". Pass index=False, or index=True if the index holds data.

See all rules in the pandas pack.