Skip to content

Commit

Permalink
DOC: Add comments and refactored commands
Browse files Browse the repository at this point in the history
  • Loading branch information
deflatSOCO committed Sep 26, 2018
1 parent 74a71fe commit e4badc4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,20 @@ Previous Behavior on Windows:
.. code-block:: ipython

In [1]: data = pd.DataFrame({
...: "string_with_lf":["a\nbc"],
...: "string_with_crlf":["a\r\nbc"]
...: "string_with_lf": ["a\nbc"],
...: "string_with_crlf": ["a\r\nbc"]
...: })

In [2]: data.to_csv("test.csv",index=False,line_terminator='\n')
In [2]: # When passing file PATH to to_csv, line_terminator does not work, and csv is saved with '\r\n'.
...: data.to_csv("test.csv", index=False, line_terminator='\n')

In [3]: with open("test.csv", mode='rb') as f:
...: print(f.read())
b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'

In [4]: with open("test2.csv", mode='w', newline='\n') as f:
...: data.to_csv(f,index=False,line_terminator='\n')
In [4]: # When passing file OBJECT with newline option to to_csv, line_terminator works.
...: with open("test2.csv", mode='w', newline='\n') as f:
...: data.to_csv(f, index=False, line_terminator='\n')

In [5]: with open("test2.csv", mode='rb') as f:
...: print(f.read())
Expand All @@ -238,11 +240,11 @@ New Behavior on Windows:
.. code-block:: ipython

In [1]: data = pd.DataFrame({
...: "string_with_lf":["a\nbc"],
...: "string_with_crlf":["a\r\nbc"]
...: "string_with_lf": ["a\nbc"],
...: "string_with_crlf": ["a\r\nbc"]
...: })

In [2]: data.to_csv("test.csv",index=False,line_terminator='\n')
In [2]: data.to_csv("test.csv", index=False, line_terminator='\n')

In [3]: with open("test.csv", mode='rb') as f:
...: print(f.read())
Expand All @@ -256,11 +258,11 @@ b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
.. code-block:: ipython

In [1]: data = pd.DataFrame({
...: "string_with_lf":["a\nbc"],
...: "string_with_crlf":["a\r\nbc"]
...: "string_with_lf": ["a\nbc"],
...: "string_with_crlf": ["a\r\nbc"]
...: })

In [2]: data.to_csv("test.csv",index=False)
In [2]: data.to_csv("test.csv", index=False)

In [3]: with open("test.csv", mode='rb') as f:
...: print(f.read())
Expand All @@ -273,12 +275,12 @@ b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
.. code-block:: ipython

In [1]: data = pd.DataFrame({
...: "string_with_lf":["a\nbc"],
...: "string_with_crlf":["a\r\nbc"]
...: "string_with_lf": ["a\nbc"],
...: "string_with_crlf": ["a\r\nbc"]
...: })

In [2]: with open("test2.csv", mode='w', newline='\n') as f:
...: data.to_csv(f,index=False)
...: data.to_csv(f, index=False)

In [3]: with open("test2.csv", mode='rb') as f:
...: print(f.read())
Expand Down

0 comments on commit e4badc4

Please sign in to comment.