Reputation: 22634
I know how to count the number of unique values in pandas series (one column in pandas dataframe).
pandas.Series.value_counts
But how do I check if they are all unique? Should I just compare value_counts with its length?
Upvotes: 30
Views: 47837
Reputation: 21
pd.Series([1, 2, 3, np.nan, np.nan]).dropna().is_unique
True
Will solve the problem posed by swapnil athawale
Upvotes: 2
Reputation: 31
pd.Series([1,2,3,np.nan,np.nan]).is_unique
> False
It will give False
for this which it should not.
Upvotes: 3
Reputation: 294218
IIUC, pd.Series.is_unique
pd.Series([1, 2, 3]).is_unique
True
And
pd.Series([1, 2, 2]).is_unique
False
Upvotes: 71
Reputation: 323226
You can use nunique
pd.Series([1, 2, 3]).nunique()==len(pd.Series([1, 2, 3]))
Out[62]: True
Upvotes: 4