@@ -71,7 +71,7 @@ Series can be instantiated from dicts:
7171
7272.. ipython :: python
7373
74- d = {' b' : 1 , ' a' : 0 , ' c' : 2 }
74+ d = {' b' : 1 , ' a' : 0 , ' c' : 2 }
7575 pd.Series(d)
7676
7777 .. note ::
@@ -92,7 +92,7 @@ index will be pulled out.
9292
9393.. ipython :: python
9494
95- d = {' a' : 0 ., ' b' : 1 ., ' c' : 2 .}
95+ d = {' a' : 0 ., ' b' : 1 ., ' c' : 2 .}
9696 pd.Series(d)
9797 pd.Series(d, index = [' b' , ' c' , ' d' , ' a' ])
9898
@@ -304,8 +304,8 @@ keys.
304304
305305.. ipython :: python
306306
307- d = {' one' : pd.Series([1 ., 2 ., 3 .], index = [' a' , ' b' , ' c' ]),
308- ' two' : pd.Series([1 ., 2 ., 3 ., 4 .], index = [' a' , ' b' , ' c' , ' d' ])}
307+ d = {' one' : pd.Series([1 ., 2 ., 3 .], index = [' a' , ' b' , ' c' ]),
308+ ' two' : pd.Series([1 ., 2 ., 3 ., 4 .], index = [' a' , ' b' , ' c' , ' d' ])}
309309 df = pd.DataFrame(d)
310310 df
311311
@@ -334,8 +334,8 @@ result will be ``range(n)``, where ``n`` is the array length.
334334
335335.. ipython :: python
336336
337- d = {' one' : [1 ., 2 ., 3 ., 4 .],
338- ' two' : [4 ., 3 ., 2 ., 1 .]}
337+ d = {' one' : [1 ., 2 ., 3 ., 4 .],
338+ ' two' : [4 ., 3 ., 2 ., 1 .]}
339339 pd.DataFrame(d)
340340 pd.DataFrame(d, index = [' a' , ' b' , ' c' , ' d' ])
341341
@@ -346,8 +346,8 @@ This case is handled identically to a dict of arrays.
346346
347347.. ipython :: python
348348
349- data = np.zeros((2 ,), dtype = [(' A' , ' i4' ),(' B' , ' f4' ),(' C' , ' a10' )])
350- data[:] = [(1 ,2 .,' Hello' ), (2 ,3 .," World" )]
349+ data = np.zeros((2 , ), dtype = [(' A' , ' i4' ), (' B' , ' f4' ), (' C' , ' a10' )])
350+ data[:] = [(1 , 2 ., ' Hello' ), (2 , 3 ., " World" )]
351351
352352 pd.DataFrame(data)
353353 pd.DataFrame(data, index = [' first' , ' second' ])
@@ -507,17 +507,15 @@ derived from existing columns.
507507
508508 iris = pd.read_csv(' data/iris.data' )
509509 iris.head()
510-
511- (iris.assign(sepal_ratio = iris[' SepalWidth' ] / iris[' SepalLength' ])
510+ (iris.assign(sepal_ratio = iris[' SepalWidth' ] / iris[' SepalLength' ])
512511 .head())
513512
514513 In the example above, we inserted a precomputed value. We can also pass in
515514a function of one argument to be evaluated on the DataFrame being assigned to.
516515
517516.. ipython :: python
518517
519- iris.assign(sepal_ratio = lambda x : (x[' SepalWidth' ] /
520- x[' SepalLength' ])).head()
518+ iris.assign(sepal_ratio = lambda x : (x[' SepalWidth' ] / x[' SepalLength' ])).head()
521519
522520 ``assign `` **always ** returns a copy of the data, leaving the original
523521DataFrame untouched.
@@ -532,8 +530,8 @@ greater than 5, calculate the ratio, and plot:
532530
533531 @savefig basics_assign.png
534532 (iris.query(' SepalLength > 5' )
535- .assign(SepalRatio = lambda x : x.SepalWidth / x.SepalLength,
536- PetalRatio = lambda x : x.PetalWidth / x.PetalLength)
533+ .assign(SepalRatio = lambda x : x.SepalWidth / x.SepalLength,
534+ PetalRatio = lambda x : x.PetalWidth / x.PetalLength)
537535 .plot(kind = ' scatter' , x = ' SepalRatio' , y = ' PetalRatio' ))
538536
539537 Since a function is passed in, the function is computed on the DataFrame
@@ -705,8 +703,8 @@ Boolean operators work as well:
705703
706704.. ipython :: python
707705
708- df1 = pd.DataFrame({' a' : [1 , 0 , 1 ], ' b' : [0 , 1 , 1 ] }, dtype = bool )
709- df2 = pd.DataFrame({' a' : [0 , 1 , 1 ], ' b' : [1 , 1 , 0 ] }, dtype = bool )
706+ df1 = pd.DataFrame({' a' : [1 , 0 , 1 ], ' b' : [0 , 1 , 1 ]}, dtype = bool )
707+ df2 = pd.DataFrame({' a' : [0 , 1 , 1 ], ' b' : [1 , 1 , 0 ]}, dtype = bool )
710708 df1 & df2
711709 df1 | df2
712710 df1 ^ df2
@@ -746,7 +744,7 @@ Similarly, the dot method on Series implements dot product:
746744
747745.. ipython :: python
748746
749- s1 = pd.Series(np.arange(5 ,10 ))
747+ s1 = pd.Series(np.arange(5 , 10 ))
750748 s1.dot(s1)
751749
752750 DataFrame is not intended to be a drop-in replacement for ndarray as its
@@ -777,7 +775,7 @@ R package):
777775 :okwarning:
778776
779777 # restore GlobalPrintConfig
780- pd.reset_option(' ^display\.' )
778+ pd.reset_option(r ' ^ display\. ' )
781779
782780 However, using ``to_string `` will return a string representation of the
783781DataFrame in tabular form, though it won't always fit the console width:
@@ -798,22 +796,22 @@ option:
798796
799797.. ipython :: python
800798
801- pd.set_option(' display.width' , 40 ) # default is 80
799+ pd.set_option(' display.width' , 40 ) # default is 80
802800
803801 pd.DataFrame(np.random.randn(3 , 12 ))
804802
805803 You can adjust the max width of the individual columns by setting ``display.max_colwidth ``
806804
807805.. ipython :: python
808806
809- datafile= {' filename' : [' filename_01' ,' filename_02' ],
810- ' path' : [" media/user_name/storage/folder_01/filename_01" ,
811- " media/user_name/storage/folder_02/filename_02" ]}
807+ datafile = {' filename' : [' filename_01' , ' filename_02' ],
808+ ' path' : [" media/user_name/storage/folder_01/filename_01" ,
809+ " media/user_name/storage/folder_02/filename_02" ]}
812810
813- pd.set_option(' display.max_colwidth' ,30 )
811+ pd.set_option(' display.max_colwidth' , 30 )
814812 pd.DataFrame(datafile)
815813
816- pd.set_option(' display.max_colwidth' ,100 )
814+ pd.set_option(' display.max_colwidth' , 100 )
817815 pd.DataFrame(datafile)
818816
819817 .. ipython :: python
@@ -833,8 +831,8 @@ accessed like an attribute:
833831
834832.. ipython :: python
835833
836- df = pd.DataFrame({' foo1' : np.random.randn(5 ),
837- ' foo2' : np.random.randn(5 )})
834+ df = pd.DataFrame({' foo1' : np.random.randn(5 ),
835+ ' foo2' : np.random.randn(5 )})
838836 df
839837 df.foo1
840838
@@ -843,7 +841,7 @@ completion mechanism so they can be tab-completed:
843841
844842.. code-block :: ipython
845843
846- In [5]: df.fo<TAB>
844+ In [5]: df.fo<TAB> # noqa: E225, E999
847845 df.foo1 df.foo2
848846
849847 .. _basics.panel :
@@ -890,8 +888,8 @@ From dict of DataFrame objects
890888.. ipython :: python
891889 :okwarning:
892890
893- data = {' Item1' : pd.DataFrame(np.random.randn(4 , 3 )),
894- ' Item2' : pd.DataFrame(np.random.randn(4 , 2 ))}
891+ data = {' Item1' : pd.DataFrame(np.random.randn(4 , 3 )),
892+ ' Item2' : pd.DataFrame(np.random.randn(4 , 2 ))}
895893 pd.Panel(data)
896894
897895 Note that the values in the dict need only be **convertible to
@@ -947,8 +945,9 @@ From DataFrame using ``to_panel`` method
947945.. ipython :: python
948946 :okwarning:
949947
950- midx = pd.MultiIndex(levels = [[' one' , ' two' ], [' x' ,' y' ]], codes = [[1 ,1 ,0 ,0 ],[1 ,0 ,1 ,0 ]])
951- df = pd.DataFrame({' A' : [1 , 2 , 3 , 4 ], ' B' : [5 , 6 , 7 , 8 ]}, index = midx)
948+ midx = pd.MultiIndex(levels = [[' one' , ' two' ], [' x' , ' y' ]],
949+ codes = [[1 , 1 , 0 , 0 ], [1 , 0 , 1 , 0 ]])
950+ df = pd.DataFrame({' A' : [1 , 2 , 3 , 4 ], ' B' : [5 , 6 , 7 , 8 ]}, index = midx)
952951 df.to_panel()
953952
954953 .. _dsintro.panel_item_selection :
0 commit comments