Skip to content

Commit cbe7d74

Browse files
committed
Merge pull request #6304 from mazieres/patch-1
Add example section to groupby.rst and one example
2 parents 186491f + 82e6d70 commit cbe7d74

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

doc/source/groupby.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,14 @@ To see the order in which each row appears within its group, use the
722722
723723
df.groupby('A').cumcount()
724724
725-
df.groupby('A').cumcount(ascending=False) # kwarg only
725+
df.groupby('A').cumcount(ascending=False) # kwarg only
726+
727+
Examples
728+
~~~~~~~~
729+
730+
Regroup columns of a DataFrame according to their sum, and sum the aggregated ones.
731+
732+
.. ipython:: python
733+
734+
df = pd.DataFrame({'a':[1,0,0], 'b':[0,1,0], 'c':[1,0,0], 'd':[2,3,4]})
735+
df.groupby(df.sum(), axis=1).sum()

0 commit comments

Comments
 (0)