Count unique values per groups with Pandas

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 Answers: Thank you … Read more

pandas unique values multiple columns

df = pd.DataFrame({'Col1': ['Bob', 'Joe', 'Bill', 'Mary', 'Joe'], 'Col2': ['Joe', 'Steve', 'Bob', 'Bob', 'Steve'], 'Col3': np.random.random(5)}) What is the best way to return the unique values of ‘Col1’ and ‘Col2’? The desired output is 'Bob', 'Joe', 'Bill', 'Mary', 'Steve' Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers … Read more