Skip to content

Clarify encoding kwarg on to_csv #8857

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

Merged
merged 1 commit into from
Nov 20, 2014
Merged
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
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,8 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
mode : str
Python write mode, default 'w'
encoding : string, optional
a string representing the encoding to use if the contents are
non-ascii, for python versions prior to 3
A string representing the encoding to use in the output file,
defaults to 'ascii' on Python 2 and 'utf-8' on Python 3.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually defaults to the sys.encoding (which has those defaults) IIRC. maybe need someone non-us to verify this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on the semantics for Python 3, but for Python 2 the csv modules does ASCII only (or at least doesn't mention sys.encoding at all), not sure if we've changed the defaults internally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default encoding is indeed ascii for py2 and utf-8 for py3. There is a way to change that but it involves quite a bit of magic: http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python

line_terminator : string, default '\\n'
The newline character or character sequence to use in the output
file
Expand Down