Skip to content

always use UnicodeWriter for csv, default to utf-8 #2006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None,

def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
cols=None, header=True, index=True, index_label=None,
mode='w', nanRep=None, encoding=None, quoting=None):
mode='w', nanRep=None, encoding='utf-8', quoting=None):
"""
Write DataFrame to a comma-separated values (csv) file

Expand Down Expand Up @@ -1168,13 +1168,10 @@ def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
quoting = csv.QUOTE_MINIMAL

try:
if encoding is not None:
csvout = com.UnicodeWriter(f, lineterminator='\n',
delimiter=sep, encoding=encoding,
quoting=quoting)
else:
csvout = csv.writer(f, lineterminator='\n', delimiter=sep,
quoting=quoting)
csvout = com.UnicodeWriter(f, lineterminator='\n',
delimiter=sep, encoding=encoding,
quoting=quoting)

self._helper_csvexcel(csvout, na_rep=na_rep,
float_format=float_format, cols=cols,
header=header, index=index,
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ def max(self, axis=None, out=None, skipna=True, level=None):

@Substitution(name='standard deviation', shortname='stdev',
na_action=_doc_exclude_na, extras='')
@Appender(_stat_doc +
@Appender(_stat_doc +
"""
Normalized by N-1 (unbiased estimator).
""")
Expand All @@ -1164,7 +1164,7 @@ def std(self, axis=None, dtype=None, out=None, ddof=1, skipna=True,

@Substitution(name='variance', shortname='var',
na_action=_doc_exclude_na, extras='')
@Appender(_stat_doc +
@Appender(_stat_doc +
"""
Normalized by N-1 (unbiased estimator).
""")
Expand Down Expand Up @@ -2419,7 +2419,7 @@ def from_csv(cls, path, sep=',', parse_dates=True, header=None,

def to_csv(self, path, index=True, sep=",", na_rep='',
float_format=None, header=False,
index_label=None, mode='w', nanRep=None, encoding=None):
index_label=None, mode='w', nanRep=None, encoding='utf-8'):
"""
Write Series to a comma-separated values (csv) file

Expand Down