Back2Basics
Back2Basics

Reputation: 7806

Dask Dataframe groupby has no len()

If you have a groupby object based on a dask dataframe why does len(<groupby object>) return an error? (bug or feature)

Upvotes: 5

Views: 380

Answers (1)

MRocklin
MRocklin

Reputation: 57251

This just hasn't been implemented. You might want to raise an issue (or better yet, a pull request). Pragmatically I would just call nunique on your grouping object

Before

g = df.groupby(df.x + df.y)
result = len(g)

After

result = (df.x + df.y).nunique()

Operationally this is nicer because it can be lazy (the result of len in Python must be a concrete integer) and because you can choose the nunique_approx variant, which will be far faster.

Upvotes: 3

Related Questions