Issue
I have a dataframe with many column and I am trying to get the columns where all values are unique (distinct).
I was able to to this for columns without missing values:
df.columns[df.nunique(dropna=False) == len(df)]
But I can't find a simple solution for columns with NaNs
Solution
nunique
and count
df.columns[df.nunique() == df.count()]
How this works?
nunique
counts theunique
values (excluding NaN's)count
as the name suggests counts all the values (excluding NaN's)
Answered By - Shubham Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.