@@ -4413,10 +4413,12 @@ def pivot(self, index=None, columns=None, values=None):
4413
4413
list can contain any of the other types (except list).
4414
4414
Keys to group by on the pivot table column. If an array is passed,
4415
4415
it is being used as the same manner as column values.
4416
- aggfunc : function or list of functions, default numpy.mean
4416
+ aggfunc : function, list of functions, dict , default numpy.mean
4417
4417
If list of functions passed, the resulting pivot table will have
4418
4418
hierarchical columns whose top level are the function names
4419
4419
(inferred from the function objects themselves)
4420
+ If dict is passed, the key is column to aggregate and value
4421
+ is function or list of functions
4420
4422
fill_value : scalar, default None
4421
4423
Value to replace missing values with
4422
4424
margins : boolean, default False
@@ -4452,14 +4454,35 @@ def pivot(self, index=None, columns=None, values=None):
4452
4454
>>> table = pivot_table(df, values='D', index=['A', 'B'],
4453
4455
... columns=['C'], aggfunc=np.sum)
4454
4456
>>> table
4455
- ... # doctest: +NORMALIZE_WHITESPACE
4456
4457
C large small
4457
4458
A B
4458
4459
bar one 4.0 5.0
4459
4460
two 7.0 6.0
4460
4461
foo one 4.0 1.0
4461
4462
two NaN 6.0
4462
4463
4464
+ >>> table = pivot_table(df, values='D', index=['A', 'B'],
4465
+ ... columns=['C'], aggfunc=np.sum)
4466
+ >>> table
4467
+ C large small
4468
+ A B
4469
+ bar one 4.0 5.0
4470
+ two 7.0 6.0
4471
+ foo one 4.0 1.0
4472
+ two NaN 6.0
4473
+
4474
+ >>> table = pivot_table(df, values=['D', 'E'], index=['A', 'C'],
4475
+ ... aggfunc={'D': np.mean,
4476
+ ... 'E': [min, max, np.mean]})
4477
+ >>> table
4478
+ D E
4479
+ mean max median min
4480
+ A C
4481
+ bar large 5.500000 16 14.5 13
4482
+ small 5.500000 15 14.5 14
4483
+ foo large 2.000000 10 9.5 9
4484
+ small 2.333333 12 11.0 8
4485
+
4463
4486
Returns
4464
4487
-------
4465
4488
table : DataFrame
0 commit comments