dtoolkit.accessor.dataframe.groupby_index#

dtoolkit.accessor.dataframe.groupby_index(df: DataFrame, /, **kwargs) DataFrameGroupBy[source]#

Group DataFrame by its index.

Parameters:
**kwargs

See the documentation for groupby() for complete details on the keyword arguments except by.

Returns:
DataFrameGroupBy

Notes

by parameter is set to df.index and can’t be overridden.

Examples

>>> import dtoolkit
>>> import pandas as pd
>>> df = pd.DataFrame({'a': [1, 1, 1], 'b': [1, 2, 3]}, index=['a', 'b', 'a'])
>>> df
   a  b
a  1  1
b  1  2
a  1  3
>>> df.groupby_index().sum()
   a  b
a  2  4
b  1  2