Find unique values in a Pandas dataframe, irrespective of row or column location
Or you can use:
df.stack().unique()
Then you don't need to worry if you have NaN values, as they are excluded when doing the stacking.
I have a Pandas dataframe and I want to find all the unique values in that dataframe...irrespective of row/columns. If I have a 10 x 10 dataframe, and suppose they have 84 unique values, I need to find them - Not the count.
I can create a set and add the values of each rows by iterating over the rows of the dataframe. But, I feel that it may be inefficient (cannot justify that). Is there an efficient way to find it? Is there a predefined function?