@@ -171,7 +171,7 @@ In ``pandas`` we may use :meth:`~pandas.pivot_table` method to handle this:
171
171
' player' : random.sample(list (string.ascii_lowercase),25 ),
172
172
' batting avg' : np.random.uniform(.200 , .400 , 25 )
173
173
})
174
- baseball.pivot_table(values = ' batting avg' , cols = ' team' , aggfunc = np.max)
174
+ baseball.pivot_table(values = ' batting avg' , columns = ' team' , aggfunc = np.max)
175
175
176
176
For more details and examples see :ref: `the reshaping documentation
177
177
<reshaping.pivot>`.
@@ -402,8 +402,8 @@ In Python the best way is to make use of :meth:`~pandas.pivot_table`:
402
402
' week' : [1 ,2 ]* 6
403
403
})
404
404
mdf = pd.melt(df, id_vars = [' month' , ' week' ])
405
- pd.pivot_table(mdf, values = ' value' , rows = [' variable' ,' week' ],
406
- cols = [' month' ], aggfunc = np.mean)
405
+ pd.pivot_table(mdf, values = ' value' , index = [' variable' ,' week' ],
406
+ columns = [' month' ], aggfunc = np.mean)
407
407
408
408
Similarly for ``dcast `` which uses a data.frame called ``df `` in R to
409
409
aggregate information based on ``Animal `` and ``FeedType ``:
@@ -433,7 +433,7 @@ using :meth:`~pandas.pivot_table`:
433
433
' Amount' : [10 , 7 , 4 , 2 , 5 , 6 , 2 ],
434
434
})
435
435
436
- df.pivot_table(values = ' Amount' , rows = ' Animal' , cols = ' FeedType' , aggfunc = ' sum' )
436
+ df.pivot_table(values = ' Amount' , index = ' Animal' , columns = ' FeedType' , aggfunc = ' sum' )
437
437
438
438
The second approach is to use the :meth: `~pandas.DataFrame.groupby ` method:
439
439
0 commit comments