Skip to content

pandas/to-csv-index

Rule to-csv-index
Pack pandas
Severity warning
Fix none, edit by hand
Library versions every version

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 has no automatic fix, so make the change by hand.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

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.

Browse the other rules of the pandas pack.