Count Unique Values by Group in Column of pandas DataFrame in Python (Example) | nunique() Function

preview_player
Показать описание
Python code of this video:

import pandas as pd # Import pandas

data = pd.DataFrame({'values':[1, 2, 3, 1, 1, 1, 1, 2, 2], # Create example DataFrame
'groups':['a', 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'c']})
print(data) # Print example DataFrame

print(count_unique) # Print count of unique values
# groups
# a 3
# b 1
# c 2
# Name: values, dtype: int64

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

very helpful thanks... how can i view SUM of unique counts? is there a way

royasalehzai