@@ -105,9 +105,7 @@ and the values are the data.
105
105
106
106
.. ipython :: python
107
107
108
- df = pd.DataFrame({
109
- ' x' : [1 , 3 , 5 ],
110
- ' y' : [2 , 4 , 6 ]})
108
+ df = pd.DataFrame({' x' : [1 , 3 , 5 ], ' y' : [2 , 4 , 6 ]})
111
109
df
112
110
113
111
@@ -131,7 +129,8 @@ The pandas method is :func:`read_csv`, which works similarly.
131
129
132
130
.. ipython :: python
133
131
134
- url = ' https://raw.github.com/pandas-dev/pandas/master/pandas/tests/data/tips.csv'
132
+ url = (' https://raw.github.com/pandas-dev/'
133
+ ' pandas/master/pandas/tests/data/tips.csv' )
135
134
tips = pd.read_csv(url)
136
135
tips.head()
137
136
@@ -289,17 +288,17 @@ see the :ref:`timeseries documentation<timeseries>` for more details.
289
288
tips[' date1_year' ] = tips[' date1' ].dt.year
290
289
tips[' date2_month' ] = tips[' date2' ].dt.month
291
290
tips[' date1_next' ] = tips[' date1' ] + pd.offsets.MonthBegin()
292
- tips[' months_between' ] = (tips[ ' date2 ' ].dt.to_period( ' M ' ) -
293
- tips[' date1' ].dt.to_period(' M' ))
291
+ tips[' months_between' ] = (
292
+ tips[ ' date2 ' ].dt.to_period( ' M ' ) - tips[' date1' ].dt.to_period(' M' ))
294
293
295
- tips[[' date1' ,' date2' ,' date1_year' ,' date2_month' ,
296
- ' date1_next' ,' months_between' ]].head()
294
+ tips[[' date1' , ' date2' , ' date1_year' , ' date2_month' ,
295
+ ' date1_next' , ' months_between' ]].head()
297
296
298
297
.. ipython :: python
299
298
:suppress:
300
299
301
- tips = tips.drop([' date1' ,' date2' ,' date1_year' ,
302
- ' date2_month' ,' date1_next' ,' months_between' ], axis = 1 )
300
+ tips = tips.drop([' date1' , ' date2' , ' date1_year' ,
301
+ ' date2_month' , ' date1_next' , ' months_between' ], axis = 1 )
303
302
304
303
Selection of Columns
305
304
~~~~~~~~~~~~~~~~~~~~
@@ -335,7 +334,7 @@ The same operations are expressed in pandas below.
335
334
tips.drop(' sex' , axis = 1 ).head()
336
335
337
336
# rename
338
- tips.rename(columns = {' total_bill' :' total_bill_2' }).head()
337
+ tips.rename(columns = {' total_bill' : ' total_bill_2' }).head()
339
338
340
339
341
340
Sorting by Values
@@ -508,7 +507,7 @@ The following tables will be used in the merge examples
508
507
' value' : np.random.randn(4 )})
509
508
df1
510
509
df2 = pd.DataFrame({' key' : [' B' , ' D' , ' D' , ' E' ],
511
- ' value' : np.random.randn(4 )})
510
+ ' value' : np.random.randn(4 )})
512
511
df2
513
512
514
513
In SAS, data must be explicitly sorted before merging. Different
@@ -695,7 +694,7 @@ In pandas this would be written as:
695
694
696
695
.. ipython :: python
697
696
698
- tips.groupby([' sex' ,' smoker' ]).first()
697
+ tips.groupby([' sex' , ' smoker' ]).first()
699
698
700
699
701
700
Other Considerations
0 commit comments