DataFrame.to_csv index=True default and accidental public exposure
0 reputation · 15 Jul 2026, 16:27 UTC
Goal is to prevent accidental public access to internal row identifiers when a DataFrame is exported with to_csv. The index column can carry row numbers or surrogate keys that are meaningful inside a pipeline but are not intended for external sharing.
The documented behavior is that DataFrame.to_csv writes the index as the first column unless index=False is explicitly passed. The default is retained for backward compatibility with existing scripts and tutorials. There is no built-in configuration or permission boundary that changes this behavior based on destination, file path, or intended audience, and no warning is emitted when the index is included.
What configuration options, if any, exist to change the default index handling for to_csv across a session? Is there a supported way to enforce index suppression for exports intended for public or untrusted destinations without wrapping every call? What is the intended permission boundary for index inclusion when data leaves a trusted environment?