@@ -252,7 +252,7 @@ convenient way to apply users' predefined styling functions, and can help reduce
252252
253253.. ipython :: python
254254
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 ]})
256256
257257 def format_and_align (styler ):
258258 return (styler.format({' N' : ' {:, } ' , ' X' : ' {:.1% } ' })
@@ -282,8 +282,7 @@ See the :ref:`Merge, join, and concatenate
282282
283283
284284 left = pd.DataFrame({' A' : [' A0' , ' A1' , ' A2' ],
285- ' B' : [' B0' , ' B1' , ' B2' ]},
286- index = index_left)
285+ ' B' : [' B0' , ' B1' , ' B2' ]}, index = index_left)
287286
288287
289288 index_right = pd.MultiIndex.from_tuples([(' K0' , ' Y0' ), (' K1' , ' Y1' ),
@@ -292,11 +291,9 @@ See the :ref:`Merge, join, and concatenate
292291
293292
294293 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)
297295
298-
299- left.join(right)
296+ left.join(right)
300297
301298 For earlier versions this can be done using the following.
302299
@@ -441,26 +438,26 @@ Previous Behavior on Windows:
441438
442439.. code-block :: ipython
443440
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"]})
448443
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')
452448
453449 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'
456452
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')
460457
461458 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'
464461
465462
466463 New Behavior on Windows:
@@ -471,16 +468,14 @@ New Behavior on Windows:
471468
472469 .. code-block :: ipython
473470
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"]})
478473
479474 In [2]: data.to_csv("test.csv", index=False, line_terminator='\n')
480475
481476 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'
484479
485480
486481 - On Windows, the value of ``os.linesep `` is ``'\r\n' ``,
@@ -489,34 +484,30 @@ New Behavior on Windows:
489484
490485 .. code-block :: ipython
491486
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"]})
496489
497490 In [2]: data.to_csv("test.csv", index=False)
498491
499492 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'
502495
503496
504497 - For files objects, specifying ``newline `` is not sufficient to set the line terminator.
505498 You must pass in the ``line_terminator `` explicitly, even in this case.
506499
507500 .. code-block :: ipython
508501
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"]})
513504
514505 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)
516507
517508 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'
520511
521512 .. _whatsnew_0240.api.timezone_offset_parsing :
522513
@@ -563,7 +554,8 @@ Parsing datetime strings with different UTC offsets will now create an Index of
563554
564555.. ipython :: python
565556
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" ])
567559 idx
568560 idx[0 ]
569561 idx[1 ]
@@ -573,7 +565,8 @@ that the dates have been converted to UTC
573565
574566.. ipython :: python
575567
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 )
577570
578571 .. _whatsnew_0240.api_breaking.calendarday :
579572
@@ -845,7 +838,7 @@ Previous Behavior:
845838 In [4]: df = pd.DataFrame(arr)
846839
847840 In [5]: df == arr[[0], :]
848- ...: # comparison previously broadcast where arithmetic would raise
841+ ...: # comparison previously broadcast where arithmetic would raise
849842 Out[5]:
850843 0 1
851844 0 True True
@@ -856,8 +849,8 @@ Previous Behavior:
856849 ValueError: Unable to coerce to DataFrame, shape must be (3, 2): given (1, 2)
857850
858851 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
861854 ...
862855 ValueError: Invalid broadcasting comparison [(1, 2)] with block values
863856 In [8]: df + (1, 2)
@@ -868,8 +861,8 @@ Previous Behavior:
868861 2 5 7
869862
870863 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
873866 Out[9]:
874867 0 1
875868 0 False True
@@ -1032,7 +1025,8 @@ Current Behavior:
10321025
10331026.. code-block :: ipython
10341027
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],
10361030 ...: 'c': [1, 1, np.nan, 1, 1]})
10371031 In [4]: pd.crosstab(df.a, df.b, normalize='columns')
10381032
0 commit comments