Count unique values per groups with Pandas [duplicate]

I need to count unique ID values in every domain.

I have data:

ID, domain
123, 'vk.com'
123, 'vk.com'
123, 'twitter.com'
456, 'vk.com'
456, 'facebook.com'
456, 'vk.com'
456, 'google.com'
789, 'twitter.com'
789, 'vk.com'

I try df.groupby(['domain', 'ID']).count()

But I want to get

domain, count
vk.com   3
twitter.com   2
facebook.com   1
google.com   1

4 Answers
4

Leave a Comment