Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Data Science by (17.6k points)

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

1 Answer

+1 vote
by (41.4k points)

Use df.domain.value_counts():

>>> df.domain.value_counts()

vk.com          5

twitter.com     2

google.com      1

facebook.com    1

Name: domain, dtype: int64

If you are interested in learning Pandas and want to become an expert in Python Programming, then check out this Python Course and upskill yourself.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...