count unique values in array python code example
Example 1: how to count number of unique values in a column python
pd.value_counts(df.Account_Type)
Gold 3
Platinum 1
Name: Account_Type, dtype: int64
Example 2: python count number of unique elements in a list
len(set(my_list))
my_list = ['so', 'so', 'so', 'many', 'duplicated', 'words']
len(set(my_list))
--> 4
Example 3: count unique values pandas
df['hID'].nunique()
5
Example 4: count unique values in python
aa="XXYYYSBAA"
bb=dict(zip(list(aa),[list(aa).count(i) for i in list(aa)]))
print(bb)
Example 5: count unique values in python
words = ['a', 'b', 'c', 'a']
unique_words = set(words)
unique_word_count = len(unique_words)