How to count unique values in aggregation in koalas

Viewed 415

New to koalas and trying to do something really basic. I am simply trying to count the unique values in a column in an aggregation. In pandas I would do:

df.groupby('columnname').agg({'column_i_want_count_of_unique_values' : pd.Series.nunique})

But for example ks.Series.nunique doesn't work and 'count' also does not seem to give the right answer.

Pretty frustrating for something so simple and common, and annoying that I can't seem to find it in the documentation for something that bills itself as porting pandas to spark.

2 Answers

You can use the function nunique

df.groupby('columnname')['column_i_want_count_of_unique_values'].nunique()
Related