count unique valin a column python code example
Example 1: pandas count the number of unique values in a column
df['hID'].nunique()
5
Example 2: count unique values in python
aa="XXYYYSBAA"
bb=dict(zip(list(aa),[list(aa).count(i) for i in list(aa)]))
print(bb)
# output:
# {'X': 2, 'Y': 3, 'S': 1, 'B': 1, 'A': 2}