@@ -274,7 +274,7 @@ convenient way to apply users' predefined styling functions, and can help reduce
274
274
275
275
.. ipython :: python
276
276
277
- df = pandas .DataFrame({' N' : [1250 , 1500 , 1750 ], ' X' : [0.25 , 0.35 , 0.50 ]})
277
+ df = pd .DataFrame({' N' : [1250 , 1500 , 1750 ], ' X' : [0.25 , 0.35 , 0.50 ]})
278
278
279
279
def format_and_align (styler ):
280
280
return (styler.format({' N' : ' {:, } ' , ' X' : ' {:.1% } ' })
@@ -304,8 +304,7 @@ See the :ref:`Merge, join, and concatenate
304
304
305
305
306
306
left = pd.DataFrame({' A' : [' A0' , ' A1' , ' A2' ],
307
- ' B' : [' B0' , ' B1' , ' B2' ]},
308
- index = index_left)
307
+ ' B' : [' B0' , ' B1' , ' B2' ]}, index = index_left)
309
308
310
309
311
310
index_right = pd.MultiIndex.from_tuples([(' K0' , ' Y0' ), (' K1' , ' Y1' ),
@@ -314,11 +313,9 @@ See the :ref:`Merge, join, and concatenate
314
313
315
314
316
315
right = pd.DataFrame({' C' : [' C0' , ' C1' , ' C2' , ' C3' ],
317
- ' D' : [' D0' , ' D1' , ' D2' , ' D3' ]},
318
- index = index_right)
316
+ ' D' : [' D0' , ' D1' , ' D2' , ' D3' ]}, index = index_right)
319
317
320
-
321
- left.join(right)
318
+ left.join(right)
322
319
323
320
For earlier versions this can be done using the following.
324
321
@@ -463,26 +460,26 @@ Previous Behavior on Windows:
463
460
464
461
.. code-block :: ipython
465
462
466
- In [1]: data = pd.DataFrame({
467
- ...: "string_with_lf": ["a\nbc"],
468
- ...: "string_with_crlf": ["a\r\nbc"]
469
- ...: })
463
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
464
+ ...: "string_with_crlf": ["a\r\nbc"]})
470
465
471
- In [2]: # When passing file PATH to to_csv, line_terminator does not work, and csv is saved with '\r\n'.
472
- ...: # Also, this converts all '\n's in the data to '\r\n'.
473
- ...: data.to_csv("test.csv", index=False, line_terminator='\n')
466
+ In [2]: # When passing file PATH to to_csv,
467
+ ...: # line_terminator does not work, and csv is saved with '\r\n'.
468
+ ...: # Also, this converts all '\n's in the data to '\r\n'.
469
+ ...: data.to_csv("test.csv", index=False, line_terminator='\n')
474
470
475
471
In [3]: with open("test.csv", mode='rb') as f:
476
- ...: print(f.read())
477
- b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
472
+ ...: print(f.read())
473
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\r\nbc","a\r\r\nbc"\r\n'
478
474
479
- In [4]: # When passing file OBJECT with newline option to to_csv, line_terminator works.
480
- ...: with open("test2.csv", mode='w', newline='\n') as f:
481
- ...: data.to_csv(f, index=False, line_terminator='\n')
475
+ In [4]: # When passing file OBJECT with newline option to
476
+ ...: # to_csv, line_terminator works.
477
+ ...: with open("test2.csv", mode='w', newline='\n') as f:
478
+ ...: data.to_csv(f, index=False, line_terminator='\n')
482
479
483
480
In [5]: with open("test2.csv", mode='rb') as f:
484
- ...: print(f.read())
485
- b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
481
+ ...: print(f.read())
482
+ Out[5]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
486
483
487
484
488
485
New Behavior on Windows:
@@ -493,16 +490,14 @@ New Behavior on Windows:
493
490
494
491
.. code-block :: ipython
495
492
496
- In [1]: data = pd.DataFrame({
497
- ...: "string_with_lf": ["a\nbc"],
498
- ...: "string_with_crlf": ["a\r\nbc"]
499
- ...: })
493
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
494
+ ...: "string_with_crlf": ["a\r\nbc"]})
500
495
501
496
In [2]: data.to_csv("test.csv", index=False, line_terminator='\n')
502
497
503
498
In [3]: with open("test.csv", mode='rb') as f:
504
- ...: print(f.read())
505
- b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
499
+ ...: print(f.read())
500
+ Out[3]: b'string_with_lf,string_with_crlf\n"a\nbc","a\r\nbc"\n'
506
501
507
502
508
503
- On Windows, the value of ``os.linesep `` is ``'\r\n' ``,
@@ -511,34 +506,30 @@ New Behavior on Windows:
511
506
512
507
.. code-block :: ipython
513
508
514
- In [1]: data = pd.DataFrame({
515
- ...: "string_with_lf": ["a\nbc"],
516
- ...: "string_with_crlf": ["a\r\nbc"]
517
- ...: })
509
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
510
+ ...: "string_with_crlf": ["a\r\nbc"]})
518
511
519
512
In [2]: data.to_csv("test.csv", index=False)
520
513
521
514
In [3]: with open("test.csv", mode='rb') as f:
522
- ...: print(f.read())
523
- b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
515
+ ...: print(f.read())
516
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
524
517
525
518
526
519
- For files objects, specifying ``newline `` is not sufficient to set the line terminator.
527
520
You must pass in the ``line_terminator `` explicitly, even in this case.
528
521
529
522
.. code-block :: ipython
530
523
531
- In [1]: data = pd.DataFrame({
532
- ...: "string_with_lf": ["a\nbc"],
533
- ...: "string_with_crlf": ["a\r\nbc"]
534
- ...: })
524
+ In [1]: data = pd.DataFrame({"string_with_lf": ["a\nbc"],
525
+ ...: "string_with_crlf": ["a\r\nbc"]})
535
526
536
527
In [2]: with open("test2.csv", mode='w', newline='\n') as f:
537
- ...: data.to_csv(f, index=False)
528
+ ...: data.to_csv(f, index=False)
538
529
539
530
In [3]: with open("test2.csv", mode='rb') as f:
540
- ...: print(f.read())
541
- b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
531
+ ...: print(f.read())
532
+ Out[3]: b'string_with_lf,string_with_crlf\r\n"a\nbc","a\r\nbc"\r\n'
542
533
543
534
.. _whatsnew_0240.api.timezone_offset_parsing :
544
535
@@ -585,7 +576,8 @@ Parsing datetime strings with different UTC offsets will now create an Index of
585
576
586
577
.. ipython :: python
587
578
588
- idx = pd.to_datetime([" 2015-11-18 15:30:00+05:30" , " 2015-11-18 16:30:00+06:30" ])
579
+ idx = pd.to_datetime([" 2015-11-18 15:30:00+05:30" ,
580
+ " 2015-11-18 16:30:00+06:30" ])
589
581
idx
590
582
idx[0 ]
591
583
idx[1 ]
@@ -595,7 +587,8 @@ that the dates have been converted to UTC
595
587
596
588
.. ipython :: python
597
589
598
- pd.to_datetime([" 2015-11-18 15:30:00+05:30" , " 2015-11-18 16:30:00+06:30" ], utc = True )
590
+ pd.to_datetime([" 2015-11-18 15:30:00+05:30" ,
591
+ " 2015-11-18 16:30:00+06:30" ], utc = True )
599
592
600
593
.. _whatsnew_0240.api_breaking.calendarday :
601
594
@@ -867,7 +860,7 @@ Previous Behavior:
867
860
In [4]: df = pd.DataFrame(arr)
868
861
869
862
In [5]: df == arr[[0], :]
870
- ...: # comparison previously broadcast where arithmetic would raise
863
+ ...: # comparison previously broadcast where arithmetic would raise
871
864
Out[5]:
872
865
0 1
873
866
0 True True
@@ -878,8 +871,8 @@ Previous Behavior:
878
871
ValueError: Unable to coerce to DataFrame, shape must be (3, 2): given (1, 2)
879
872
880
873
In [7]: df == (1, 2)
881
- ...: # length matches number of columns;
882
- ...: # comparison previously raised where arithmetic would broadcast
874
+ ...: # length matches number of columns;
875
+ ...: # comparison previously raised where arithmetic would broadcast
883
876
...
884
877
ValueError: Invalid broadcasting comparison [(1, 2)] with block values
885
878
In [8]: df + (1, 2)
@@ -890,8 +883,8 @@ Previous Behavior:
890
883
2 5 7
891
884
892
885
In [9]: df == (1, 2, 3)
893
- ...: # length matches number of rows
894
- ...: # comparison previously broadcast where arithmetic would raise
886
+ ...: # length matches number of rows
887
+ ...: # comparison previously broadcast where arithmetic would raise
895
888
Out[9]:
896
889
0 1
897
890
0 False True
@@ -1054,7 +1047,8 @@ Current Behavior:
1054
1047
1055
1048
.. code-block :: ipython
1056
1049
1057
- In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2], 'b': [3, 3, 4, 4, 4],
1050
+ In [3]: df = pd.DataFrame({'a': [1, 2, 2, 2, 2],
1051
+ ...: 'b': [3, 3, 4, 4, 4],
1058
1052
...: 'c': [1, 1, np.nan, 1, 1]})
1059
1053
In [4]: pd.crosstab(df.a, df.b, normalize='columns')
1060
1054
0 commit comments