@@ -45,7 +45,7 @@ a default integer index:
45
45
46
46
.. ipython :: python
47
47
48
- s = pd.Series([1 ,3 , 5 , np.nan,6 , 8 ])
48
+ s = pd.Series([1 , 3 , 5 , np.nan, 6 , 8 ])
49
49
s
50
50
51
51
Creating a :class: `DataFrame ` by passing a NumPy array, with a datetime index
@@ -62,12 +62,12 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s
62
62
63
63
.. ipython :: python
64
64
65
- df2 = pd.DataFrame({ ' A' : 1 .,
66
- ' B' : pd.Timestamp(' 20130102' ),
67
- ' C' : pd.Series(1 ,index = list (range (4 )),dtype = ' float32' ),
68
- ' D' : np.array([3 ] * 4 ,dtype = ' int32' ),
69
- ' E' : pd.Categorical([" test" ," train" ," test" ," train" ]),
70
- ' F' : ' foo' })
65
+ df2 = pd.DataFrame({' A' : 1 .,
66
+ ' B' : pd.Timestamp(' 20130102' ),
67
+ ' C' : pd.Series(1 , index = list (range (4 )),dtype = ' float32' ),
68
+ ' D' : np.array([3 ] * 4 , dtype = ' int32' ),
69
+ ' E' : pd.Categorical([" test" , " train" , " test" , " train" ]),
70
+ ' F' : ' foo' })
71
71
df2
72
72
73
73
The columns of the resulting ``DataFrame `` have different
@@ -283,9 +283,9 @@ Using the :func:`~Series.isin` method for filtering:
283
283
.. ipython :: python
284
284
285
285
df2 = df.copy()
286
- df2[' E' ] = [' one' , ' one' ,' two' ,' three' ,' four' ,' three' ]
286
+ df2[' E' ] = [' one' , ' one' , ' two' , ' three' , ' four' , ' three' ]
287
287
df2
288
- df2[df2[' E' ].isin([' two' ,' four' ])]
288
+ df2[df2[' E' ].isin([' two' , ' four' ])]
289
289
290
290
Setting
291
291
~~~~~~~
@@ -295,7 +295,7 @@ by the indexes.
295
295
296
296
.. ipython :: python
297
297
298
- s1 = pd.Series([1 ,2 , 3 , 4 , 5 , 6 ], index = pd.date_range(' 20130102' , periods = 6 ))
298
+ s1 = pd.Series([1 , 2 , 3 , 4 , 5 , 6 ], index = pd.date_range(' 20130102' , periods = 6 ))
299
299
s1
300
300
df[' F' ] = s1
301
301
@@ -394,7 +394,7 @@ In addition, pandas automatically broadcasts along the specified dimension.
394
394
395
395
.. ipython :: python
396
396
397
- s = pd.Series([1 ,3 , 5 , np.nan,6 , 8 ], index = dates).shift(2 )
397
+ s = pd.Series([1 , 3 , 5 , np.nan, 6 , 8 ], index = dates).shift(2 )
398
398
s
399
399
df.sub(s, axis = ' index' )
400
400
@@ -492,7 +492,7 @@ section.
492
492
493
493
.. ipython :: python
494
494
495
- df = pd.DataFrame(np.random.randn(8 , 4 ), columns = [' A' ,' B' ,' C' ,' D' ])
495
+ df = pd.DataFrame(np.random.randn(8 , 4 ), columns = [' A' , ' B' , ' C' , ' D' ])
496
496
df
497
497
s = df.iloc[3 ]
498
498
df.append(s, ignore_index = True )
@@ -512,12 +512,12 @@ See the :ref:`Grouping section <groupby>`.
512
512
513
513
.. ipython :: python
514
514
515
- df = pd.DataFrame({' A' : [' foo' , ' bar' , ' foo' , ' bar' ,
516
- ' foo' , ' bar' , ' foo' , ' foo' ],
517
- ' B' : [' one' , ' one' , ' two' , ' three' ,
518
- ' two' , ' two' , ' one' , ' three' ],
519
- ' C' : np.random.randn(8 ),
520
- ' D' : np.random.randn(8 )})
515
+ df = pd.DataFrame({' A' : [' foo' , ' bar' , ' foo' , ' bar' ,
516
+ ' foo' , ' bar' , ' foo' , ' foo' ],
517
+ ' B' : [' one' , ' one' , ' two' , ' three' ,
518
+ ' two' , ' two' , ' one' , ' three' ],
519
+ ' C' : np.random.randn(8 ),
520
+ ' D' : np.random.randn(8 )})
521
521
df
522
522
523
523
Grouping and then applying the :meth: `~DataFrame.sum ` function to the resulting
@@ -532,7 +532,7 @@ apply the ``sum`` function.
532
532
533
533
.. ipython :: python
534
534
535
- df.groupby([' A' ,' B' ]).sum()
535
+ df.groupby([' A' , ' B' ]).sum()
536
536
537
537
Reshaping
538
538
---------
@@ -578,11 +578,11 @@ See the section on :ref:`Pivot Tables <reshaping.pivot>`.
578
578
579
579
.. ipython :: python
580
580
581
- df = pd.DataFrame({' A' : [' one' , ' one' , ' two' , ' three' ] * 3 ,
582
- ' B' : [' A' , ' B' , ' C' ] * 4 ,
583
- ' C' : [' foo' , ' foo' , ' foo' , ' bar' , ' bar' , ' bar' ] * 2 ,
584
- ' D' : np.random.randn(12 ),
585
- ' E' : np.random.randn(12 )})
581
+ df = pd.DataFrame({' A' : [' one' , ' one' , ' two' , ' three' ] * 3 ,
582
+ ' B' : [' A' , ' B' , ' C' ] * 4 ,
583
+ ' C' : [' foo' , ' foo' , ' foo' , ' bar' , ' bar' , ' bar' ] * 2 ,
584
+ ' D' : np.random.randn(12 ),
585
+ ' E' : np.random.randn(12 )})
586
586
df
587
587
588
588
We can produce pivot tables from this data very easily:
@@ -653,7 +653,7 @@ pandas can include categorical data in a ``DataFrame``. For full docs, see the
653
653
654
654
.. ipython :: python
655
655
656
- df = pd.DataFrame({" id" :[1 ,2 , 3 , 4 , 5 , 6 ], " raw_grade" :[' a' , ' b' , ' b' , ' a' , ' a' , ' e' ]})
656
+ df = pd.DataFrame({" id" :[1 , 2 , 3 , 4 , 5 , 6 ], " raw_grade" :[' a' , ' b' , ' b' , ' a' , ' a' , ' e' ]})
657
657
658
658
Convert the raw grades to a categorical data type.
659
659
@@ -753,13 +753,13 @@ Writing to a HDF5 Store.
753
753
754
754
.. ipython :: python
755
755
756
- df.to_hdf(' foo.h5' ,' df' )
756
+ df.to_hdf(' foo.h5' , ' df' )
757
757
758
758
Reading from a HDF5 Store.
759
759
760
760
.. ipython :: python
761
761
762
- pd.read_hdf(' foo.h5' ,' df' )
762
+ pd.read_hdf(' foo.h5' , ' df' )
763
763
764
764
.. ipython :: python
765
765
:suppress:
@@ -796,7 +796,7 @@ If you are attempting to perform an operation you might see an exception like:
796
796
.. code-block :: python
797
797
798
798
>> > if pd.Series([False , True , False ]):
799
- print (" I was true" )
799
+ ... print (" I was true" )
800
800
Traceback
801
801
...
802
802
ValueError : The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
0 commit comments