Skip to content

Commit c4fa3c9

Browse files
chris-b1jorisvandenbossche
authored andcommitted
DOC: file obj for to_csv must be newline='' (#25624)
1 parent de52d0b commit c4fa3c9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

doc/source/user_guide/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ The ``Series`` and ``DataFrame`` objects have an instance method ``to_csv`` whic
16891689
allows storing the contents of the object as a comma-separated-values file. The
16901690
function takes a number of arguments. Only the first is required.
16911691

1692-
* ``path_or_buf``: A string path to the file to write or a StringIO
1692+
* ``path_or_buf``: A string path to the file to write or a file object. If a file object it must be opened with `newline=''`
16931693
* ``sep`` : Field delimiter for the output file (default ",")
16941694
* ``na_rep``: A string representation of a missing value (default '')
16951695
* ``float_format``: Format string for floating point numbers
@@ -1702,7 +1702,7 @@ function takes a number of arguments. Only the first is required.
17021702
* ``mode`` : Python write mode, default 'w'
17031703
* ``encoding``: a string representing the encoding to use if the contents are
17041704
non-ASCII, for Python versions prior to 3
1705-
* ``line_terminator``: Character sequence denoting line end (default '\\n')
1705+
* ``line_terminator``: Character sequence denoting line end (default `os.linesep`)
17061706
* ``quoting``: Set quoting rules as in csv module (default csv.QUOTE_MINIMAL). Note that if you have set a `float_format` then floats are converted to strings and csv.QUOTE_NONNUMERIC will treat them as non-numeric
17071707
* ``quotechar``: Character used to quote fields (default '"')
17081708
* ``doublequote``: Control quoting of ``quotechar`` in fields (default True)

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,8 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
29192919
----------
29202920
path_or_buf : str or file handle, default None
29212921
File path or object, if None is provided the result is returned as
2922-
a string.
2922+
a string. If a file object is passed it should be opened with
2923+
`newline=''`, disabling universal newlines.
29232924
29242925
.. versionchanged:: 0.24.0
29252926

0 commit comments

Comments
 (0)