to_csv: index and header parameter interference · Issue #6186 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
In the following snippet the two to_csv calls differs only in the index argument. Although the output header in the first case is (index), 'X', 'Y' but in the second case is 'A', 'B'. The documentation didn't suggest that sort of difference.
import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])
df.to_csv('testtocsv1.csv', header=['X', 'Y'])
df.to_csv('testtocsv2.csv', index=False, header=['X', 'Y'])