diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index 41539b5ce283e..d2f60b791eb7c 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -722,4 +722,14 @@ To see the order in which each row appears within its group, use the df.groupby('A').cumcount() - df.groupby('A').cumcount(ascending=False) # kwarg only \ No newline at end of file + df.groupby('A').cumcount(ascending=False) # kwarg only + +Examples +~~~~~~~~ + +Regroup columns of a DataFrame according to their sum, and sum the aggregated ones. + +.. ipython:: python + + df = pd.DataFrame({'a':[1,0,0], 'b':[0,1,0], 'c':[1,0,0], 'd':[2,3,4]}) + df.groupby(df.sum(), axis=1).sum()