Skip to content

Commit e4badc4

Browse files
committed
DOC: Add comments and refactored commands
1 parent 74a71fe commit e4badc4

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

doc/source/whatsnew/v0.24.0.txt

+16-14
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,20 @@ Previous Behavior on Windows:
211211
.. code-block:: ipython
212212

213213
In [1]: data = pd.DataFrame({
214-
...: "string_with_lf":["a\nbc"],
215-
...: "string_with_crlf":["a\r\nbc"]
214+
...: "string_with_lf": ["a\nbc"],
215+
...: "string_with_crlf": ["a\r\nbc"]
216216
...: })
217217

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

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

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

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

240242
In [1]: data = pd.DataFrame({
241-
...: "string_with_lf":["a\nbc"],
242-
...: "string_with_crlf":["a\r\nbc"]
243+
...: "string_with_lf": ["a\nbc"],
244+
...: "string_with_crlf": ["a\r\nbc"]
243245
...: })
244246

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

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

258260
In [1]: data = pd.DataFrame({
259-
...: "string_with_lf":["a\nbc"],
260-
...: "string_with_crlf":["a\r\nbc"]
261+
...: "string_with_lf": ["a\nbc"],
262+
...: "string_with_crlf": ["a\r\nbc"]
261263
...: })
262264

263-
In [2]: data.to_csv("test.csv",index=False)
265+
In [2]: data.to_csv("test.csv", index=False)
264266

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

275277
In [1]: data = pd.DataFrame({
276-
...: "string_with_lf":["a\nbc"],
277-
...: "string_with_crlf":["a\r\nbc"]
278+
...: "string_with_lf": ["a\nbc"],
279+
...: "string_with_crlf": ["a\r\nbc"]
278280
...: })
279281

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

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

0 commit comments

Comments
 (0)