pandas/to-csv-append-header
| Rule | to-csv-append-header |
|---|---|
| Pack | pandas |
| Severity | error |
| Fix | none, edit by hand |
| Library versions | every version |
to_csv(mode="a") writes the header again on every call, so header rows end up among the data. Pass header=False, or write the header only on the first call.
for part in parts: part.to_csv(path, mode="a", index=False) part.to_csv(path, mode="a", index=False, header=not os.path.exists(path))What the rule reports
Section titled “What the rule reports”The rule reports df.to_csv(path, mode="a") without header=, which writes the header again on every call.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
The repeated header rows are read back as data, so every number in the file comes back as text.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
to_csv with mode="a" writes the header again on every call, so the file holds header rows among the data. Pass header=False, or header=not os.path.exists(path) for the first write.Browse the other rules of the pandas pack.