Skip to content

to_csv: index and header parameter interference #6186

Closed
@sandorkazi

Description

@sandorkazi

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'])

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO CSVread_csv, to_csvOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions