0

In Pandas dataframe, I am trying to get a count of the unique values in a column for each distinct value in another column.

For instance if we have the dataframe below and we want to get the count of the unique values in starter_email column for each unique payment_email:

id       starter_email   payment_email       
22      [email protected]    [email protected]
22      [email protected]    [email protected]
30      [email protected]    [email protected]
12      [email protected]    [email protected]

The ideal output would be:

   payment_email   unique_starter_email
   [email protected]                       2
   [email protected]                       1

I know how to do the simple unique value count on 1 column only:

unique_starter_email=df['starter_email'].value_counts() 

But I wasn't sure how to get the count based on each unique value in another column. Any suggestion would be greatly appreciated!

Stanleyrr
  • 858
  • 3
  • 12
  • 31

0 Answers0