@@ -252,7 +252,7 @@ convenient way to apply users' predefined styling functions, and can help reduce
252
252
253
253
.. ipython :: python
254
254
255
- df = pandas .DataFrame({' N' : [1250 , 1500 , 1750 ], ' X' : [0.25 , 0.35 , 0.50 ]})
255
+ df = pd .DataFrame({' N' : [1250 , 1500 , 1750 ], ' X' : [0.25 , 0.35 , 0.50 ]})
256
256
257
257
def format_and_align (styler ):
258
258
return (styler.format({' N' : ' {:, } ' , ' X' : ' {:.1% } ' })
@@ -282,8 +282,7 @@ See the :ref:`Merge, join, and concatenate
282
282
283
283
284
284
left = pd.DataFrame({' A' : [' A0' , ' A1' , ' A2' ],
285
- ' B' : [' B0' , ' B1' , ' B2' ]},
286
- index = index_left)
285
+ ' B' : [' B0' , ' B1' , ' B2' ]}, index = index_left)
287
286
288
287
289
288
index_right = pd.MultiIndex.from_tuples([(' K0' , ' Y0' ), (' K1' , ' Y1' ),
@@ -292,11 +291,9 @@ See the :ref:`Merge, join, and concatenate
292
291
293
292
294
293
right = pd.DataFrame({' C' : [' C0' , ' C1' , ' C2' , ' C3' ],
295
- ' D' : [' D0' , ' D1' , ' D2' , ' D3' ]},
296
- index = index_right)
294
+ ' D' : [' D0' , ' D1' , ' D2' , ' D3' ]}, index = index_right)
297
295
298
-
299
- left.join(right)
296
+ left.join(right)
300
297
301
298
For earlier versions this can be done using the following.
302
299
@@ -441,26 +438,26 @@ Previous Behavior on Windows:
441
438
442
439
.. code-block :: ipython
443
440
444
- In [1]: data = pd.DataFrame({
445
- ...: "string_with_lf": ["a\nbc"],
446
- ...: "string_with_crlf": ["a\r\nbc"]
447
- ...: })
441
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
442
+ ...: "string_with_crlf": ["a\r\nbc"]})
448
443
449
- In [2]: # When passing file PATH to to_csv, line_terminator does not work, and csv is saved with '\r\n'.
450
- ...: # Also, this converts all '\n's in the data to '\r\n'.
451
- ...: data.to_csv("test.csv", index=False, line_terminator='\n')
444
+ In [2]: # When passing file PATH to to_csv,
445
+ ...: # line_terminator does not work, and csv is saved with '\r\n'.
446
+ ...: # Also, this converts all '\n's in the data to '\r\n'.
447
+ ...: data.to_csv("test.csv", index=False, line_terminator='\n')
452
448
453
449
In [3]: with open("test.csv", mode='rb') as f:
454
- ...: print(f.read())
455
- b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
450
+ ...: print(f.read())
451
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
456
452
457
- In [4]: # When passing file OBJECT with newline option to to_csv, line_terminator works.
458
- ...: with open("test2.csv", mode='w', newline='\n') as f:
459
- ...: data.to_csv(f, index=False, line_terminator='\n')
453
+ In [4]: # When passing file OBJECT with newline option to
454
+ ...: # to_csv, line_terminator works.
455
+ ...: with open("test2.csv", mode='w', newline='\n') as f:
456
+ ...: data.to_csv(f, index=False, line_terminator='\n')
460
457
461
458
In [5]: with open("test2.csv", mode='rb') as f:
462
- ...: print(f.read())
463
- b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
459
+ ...: print(f.read())
460
+ Out[5]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
464
461
465
462
466
463
New Behavior on Windows:
@@ -471,16 +468,14 @@ New Behavior on Windows:
471
468
472
469
.. code-block :: ipython
473
470
474
- In [1]: data = pd.DataFrame({
475
- ...: "string_with_lf": ["a\nbc"],
476
- ...: "string_with_crlf": ["a\r\nbc"]
477
- ...: })
471
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
472
+ ...: "string_with_crlf": ["a\r\nbc"]})
478
473
479
474
In [2]: data.to_csv("test.csv", index=False, line_terminator='\n')
480
475
481
476
In [3]: with open("test.csv", mode='rb') as f:
482
- ...: print(f.read())
483
- b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
477
+ ...: print(f.read())
478
+ Out[3]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
484
479
485
480
486
481
- On Windows, the value of ``os.linesep `` is ``'\r\n' ``,
@@ -489,34 +484,30 @@ New Behavior on Windows:
489
484
490
485
.. code-block :: ipython
491
486
492
- In [1]: data = pd.DataFrame({
493
- ...: "string_with_lf": ["a\nbc"],
494
- ...: "string_with_crlf": ["a\r\nbc"]
495
- ...: })
487
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
488
+ ...: "string_with_crlf": ["a\r\nbc"]})
496
489
497
490
In [2]: data.to_csv("test.csv", index=False)
498
491
499
492
In [3]: with open("test.csv", mode='rb') as f:
500
- ...: print(f.read())
501
- b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
493
+ ...: print(f.read())
494
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
502
495
503
496
504
497
- For files objects, specifying ``newline `` is not sufficient to set the line terminator.
505
498
You must pass in the ``line_terminator `` explicitly, even in this case.
506
499
507
500
.. code-block :: ipython
508
501
509
- In [1]: data = pd.DataFrame({
510
- ...: "string_with_lf": ["a\nbc"],
511
- ...: "string_with_crlf": ["a\r\nbc"]
512
- ...: })
502
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
503
+ ...: "string_with_crlf": ["a\r\nbc"]})
513
504
514
505
In [2]: with open("test2.csv", mode='w', newline='\n') as f:
515
- ...: data.to_csv(f, index=False)
506
+ ...: data.to_csv(f, index=False)
516
507
517
508
In [3]: with open("test2.csv", mode='rb') as f:
518
- ...: print(f.read())
519
- b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
509
+ ...: print(f.read())
510
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
520
511
521
512
.. _whatsnew_0240.api.timezone_offset_parsing :
522
513
@@ -563,7 +554,8 @@ Parsing datetime strings with different UTC offsets will now create an Index of
563
554
564
555
.. ipython :: python
565
556
566
- idx = pd.to_datetime([" 2015-11-18 15:30:00+05:30" , " 2015-11-18 16:30:00+06:30" ])
557
+ idx = pd.to_datetime([" 2015-11-18 15:30:00+05:30" ,
558
+ " 2015-11-18 16:30:00+06:30" ])
567
559
idx
568
560
idx[0 ]
569
561
idx[1 ]
@@ -573,7 +565,8 @@ that the dates have been converted to UTC
573
565
574
566
.. ipython :: python
575
567
576
- pd.to_datetime([" 2015-11-18 15:30:00+05:30" , " 2015-11-18 16:30:00+06:30" ], utc = True )
568
+ pd.to_datetime([" 2015-11-18 15:30:00+05:30" ,
569
+ " 2015-11-18 16:30:00+06:30" ], utc = True )
577
570
578
571
.. _whatsnew_0240.api_breaking.calendarday :
579
572
@@ -845,7 +838,7 @@ Previous Behavior:
845
838
In [4]: df = pd.DataFrame(arr)
846
839
847
840
In [5]: df == arr[[0], :]
848
- ...: # comparison previously broadcast where arithmetic would raise
841
+ ...: # comparison previously broadcast where arithmetic would raise
849
842
Out[5]:
850
843
0 1
851
844
0 True True
@@ -856,8 +849,8 @@ Previous Behavior:
856
849
ValueError: Unable to coerce to DataFrame, shape must be (3, 2): given (1, 2)
857
850
858
851
In [7]: df == (1, 2)
859
- ...: # length matches number of columns;
860
- ...: # comparison previously raised where arithmetic would broadcast
852
+ ...: # length matches number of columns;
853
+ ...: # comparison previously raised where arithmetic would broadcast
861
854
...
862
855
ValueError: Invalid broadcasting comparison [(1, 2)] with block values
863
856
In [8]: df + (1, 2)
@@ -868,8 +861,8 @@ Previous Behavior:
868
861
2 5 7
869
862
870
863
In [9]: df == (1, 2, 3)
871
- ...: # length matches number of rows
872
- ...: # comparison previously broadcast where arithmetic would raise
864
+ ...: # length matches number of rows
865
+ ...: # comparison previously broadcast where arithmetic would raise
873
866
Out[9]:
874
867
0 1
875
868
0 False True
@@ -1032,7 +1025,8 @@ Current Behavior:
1032
1025
1033
1026
.. code-block :: ipython
1034
1027
1035
- In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
1028
+ In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2],
1029
+ ...: 'b': [3, 3, 4, 4, 4],
1036
1030
...: 'c': [1, 1, np.nan, 1, 1]})
1037
1031
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
1038
1032
0 commit comments