Can i count the values of 1 column and distinct count another column?

Viewed 29

I have this line of code below

df.groupby(['ProdName','Year'])['OrderID'].count()

I was wondering how can i add another column that would do a distinct count (nunique)

1 Answers

Try this:

 df.groupby(['ProdName','Year']).agg({'OrderID': count, 'OrderID': nunique})
Related