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 1234@gmail.com gzab@aol.com
22 1234@gmail.com gzab@aol.com
30 2267@gmail.com gzab@aol.com
12 3142@gmail.com ccgc@aol.com
The ideal output would be:
payment_email unique_starter_email
gzab@aol.com 2
ccgc@aol.com 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!