Open
Description
Feature Type
- Adding new functionality to pandas
Problem Description
It would be great if Pandas could generate CSV files that Excel automatically opens with the correct delimiter. When using semicolons or other non-comma separators, Excel often opens CSV files with all data in one column unless a sep=
hint is present at the beginning of the file. Currently, users must write custom code to add this hint.
Feature Description
Add a boolean parameter excel_sep_hint
to to_csv()
that prepends a delimiter hint for Excel:
def to_csv(self, ..., excel_sep_hint=False):
"""
excel_sep_hint : bool, default False
If True, prepend 'sep=' line to help Excel detect delimiter
"""
Usage:
df.to_csv('data.csv', sep=';', excel_sep_hint=True)
Output:
sep=;
col1;col2;col3
val1;val2;val3
Alternative Solutions
Users currently write wrapper functions or handle files manually:
with open('file.csv', 'w') as f:
f.write('sep=;\n')
df.to_csv('file.csv', sep=';', mode='a')
Additional Context
The sep=
hint is a standard Excel feature for delimiter detection. This would improve pandas-Excel interoperability, especially useful in European locales where semicolons are common CSV separators.