pandas.DataFrame.pivot_table
pandas 3.1.1 · DataFrame · method
Group rows and columns into a summary table. Use aggfunc to control how repeated combinations are reduced.
Call syntax
DataFrame.pivot_table(…) Full signature
DataFrame.pivot_table(
values=None,
index=None,
columns=None,
aggfunc='mean',
fill_value=None,
margins=False,
dropna=True,
margins_name='All',
observed=True,
sort=True,
**kwargs,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
values |
Optional Positional or keyword Default None |
list-like or scalar Supply values to transform, match, aggregate, or use as data. |
index |
Optional Positional or keyword Default None |
column, Grouper, array, or sequence of the previous Supply row labels or control how existing row labels are used. |
columns |
Optional Positional or keyword Default None |
column, Grouper, array, or sequence of the previous Supply column labels or control how columns are handled. |
aggfunc |
Optional Positional or keyword Default 'mean' |
function, list of functions, dict Choose an aggregation name, callable, list, or mapping as supported. |
fill_value |
Optional Positional or keyword Default None |
scalar Supply a value to use in place of a missing position. |
margins |
Optional Positional or keyword Default False |
bool Choose whether summary totals are added for rows and columns. |
dropna |
Optional Positional or keyword Default True |
bool Choose whether to drop missing values or missing keys from consideration. |
margins_name |
Optional Positional or keyword Default 'All' |
str Set the label for summary totals. |
observed |
Optional Positional or keyword Default True |
bool When grouping categories, choose whether to keep only combinations present in the input. |
sort |
Optional Positional or keyword Default True |
bool Choose whether the resulting labels or groups are sorted where supported. |
**kwargs |
Optional Additional keyword arguments |
Returns
DataFrame