df.groupby(['col1'])['col2'].mean() # or .count(), etc. # other way for multiple statistics df.groupby(['col1', 'col2'])[['col3', 'col4']].agg(['min', 'max', 'sum']) # choose specific columns df1.groupby('col1').agg({'col2':'count'}) # use filter to count rows df.groupby('col1').filter(lambda x: len(x) > 1)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter