How to get number of groups in a groupby object in pandas?

wolfsatthedoor picture wolfsatthedoor · Jan 5, 2015 · Viewed 37.5k times · Source

This would be useful so I know how many unique groups I have to perform calculations on. Thank you.

Suppose groupby object is called dfgroup.

Answer

BrenBarn picture BrenBarn · Jan 5, 2015

As documented, you can get the number of groups with len(dfgroup).