pivot_table

The function pandas.pivot_table can be used to create spreadsheet-style pivot tables.

It takes a number of arguments:

data: A DataFrame object

values: a column or a list of columns to aggregate

index: a column, Grouper, array which has the same length as data, or list of them. Keys to group by on the pivot table index. If an array is passed, it is being used as the same manner as column values.

columns: a column, Grouper, array which has the same length as data, or list of them. Keys to group by on the pivot table column. If an array is passed, it is being used as the same manner as column values.

groupby

Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns.

by : mapping function / list of functions, dict, Series, or tuple list of column names. Called on each element of the object index to determine the groups. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups

axis : int, default 0

level : int, level name, or sequence of such, default None

If the axis is a MultiIndex (hierarchical), group by a particular level or levels

as_index : boolean, default True

For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output

sort : boolean, default True

Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. groupby preserves the order of rows within each group.

# crosstab can also be passed a third Series and an aggregation function (aggfunc) #that will be applied to the values of the third Series within each group defined by the first two Series:pd.crosstab(df_x.type,df_x.B,values=df_x.A,aggfunc=np.sum)