You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now there is no way (to my knowledge) to get the number of groups that the DataFrame.groupby() method creates. For example (using Pandas 0.4 dev):
from pandas import *; from numpy.random import randn
data = { 'A': rand(4), 'B': rand(4), 'C': (0, 1, 1, 1)}
df = DataFrame(data)
grouping = df.groupby('C')
len(grouping)
TypeError: object of 'DataFrameGroupBy' has no len()
This seems counter intuitive considering iter is implemented. Having the len() method would be very useful if we need to know the number of existing groups prior to iterating through the groups (e.g.. one use case would be to determine the number and layout of subplots, one for each group, in a Matplotlib figure).
Right now, I typically just do:
grouping = list(df.groupby('C'))
n = len(grouping)
# do something with n
for key, frame in grouping:
# do something
(updated to fix formatting)
The text was updated successfully, but these errors were encountered:
Right now there is no way (to my knowledge) to get the number of groups that the DataFrame.groupby() method creates. For example (using Pandas 0.4 dev):
This seems counter intuitive considering iter is implemented. Having the len() method would be very useful if we need to know the number of existing groups prior to iterating through the groups (e.g.. one use case would be to determine the number and layout of subplots, one for each group, in a Matplotlib figure).
Right now, I typically just do:
(updated to fix formatting)
The text was updated successfully, but these errors were encountered: