pivot_table#
- muldataframe.pivot_table(*args, **kwargs)#
Same as
pandas.pivot_tableexcept that it returns a MulDataFrame.If with the same arguments,
pandas.pivot_tablereturns a dataframe with no multiindex. Then this function will return a muldataframe with empty index and columns dataframes.Check MulDataFrame.melt for a reverse operation.
Parameters#
The parameters are exactly the same as in pandas.pivot_table. Please check its web page for detailed usage.
Returns#
- MulDataFrame
returns a MulDataFrame
Examples#
>>> import pandas as pd >>> import muldataframe as md >>> df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar"], "B": ["one", "one", "one", "two", "two", "one", "one", "two", "two"], "C": ["small", "large", "large", "small", "small", "large", "small", "small", "large"], "D": [1, 2, 2, 3, 3, 4, 5, 6, 7], "E": [2, 4, 5, 5, 6, 6, 8, 9, 9]}) >>> md.pivot_table(df, values='D', index=['A', 'B'], columns=['C'], aggfunc="sum") (4, 2) Empty DataFrame Columns: [] Index: [large, small] ----------- ----------------------- A B C large small 0 bar one 0 4.0 5.0 1 bar two 1 7.0 6.0 2 foo one 2 4.0 1.0 3 foo two 3 NaN 6.0
MulDataFrame