@@ -211,18 +211,20 @@ Previous Behavior on Windows:
211
211
.. code-block:: ipython
212
212
213
213
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"]
216
216
...: })
217
217
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')
219
220
220
221
In [3]: with open("test.csv", mode='rb') as f:
221
222
...: print(f.read())
222
223
b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
223
224
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')
226
228
227
229
In [5]: with open("test2.csv", mode='rb') as f:
228
230
...: print(f.read())
@@ -238,11 +240,11 @@ New Behavior on Windows:
238
240
.. code-block:: ipython
239
241
240
242
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"]
243
245
...: })
244
246
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')
246
248
247
249
In [3]: with open("test.csv", mode='rb') as f:
248
250
...: print(f.read())
@@ -256,11 +258,11 @@ b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
256
258
.. code-block:: ipython
257
259
258
260
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"]
261
263
...: })
262
264
263
- In [2]: data.to_csv("test.csv",index=False)
265
+ In [2]: data.to_csv("test.csv", index=False)
264
266
265
267
In [3]: with open("test.csv", mode='rb') as f:
266
268
...: print(f.read())
@@ -273,12 +275,12 @@ b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
273
275
.. code-block:: ipython
274
276
275
277
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"]
278
280
...: })
279
281
280
282
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)
282
284
283
285
In [3]: with open("test2.csv", mode='rb') as f:
284
286
...: print(f.read())
0 commit comments