Reputation: 354
I am creating a dataframe name "salesdata" and it has a column name "Outlet_Size",this column contains some missing data.This is my code-:
#defining a dictionary
cat_dict ={}
#getting all the values of the column
outlet_size_values = salesdata.Outlet_Size.values
unique_outlet_size_val = list(set(outlet_size_values))
print(unique_outlet_size_val)
the output I am getting is [nan,'High','Medium','Small'] I don't want this missing data(nan) to be the part of my list and I don;t want to create a new list for this.
Upvotes: 3
Views: 376
Reputation: 294258
You can use numpy.unique
import pandas as pd
import numpy as np
np.unique(salesdata.Outlet_Size.dropna().values)
Upvotes: 0
Reputation: 32095
Use basic pandas functions: dropna
to remove the nan values, then unique
to get the set-equivalent result:
salesdata.Outlet_Size.dropna().unique()
Upvotes: 3