简体   繁体   中英

Missing data in a column of pandas dataframe

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.

使用基本的dropna函数: dropna删除 nan 值,然后使用unique来获得集合等效结果:

salesdata.Outlet_Size.dropna().unique()

pandas has the function unique to get distinct values. You can use this and filter out NaNs like

salesdata.loc[~salesdata.Outlet_Size.isnull(), 'Outlet_Size'].unique()

You can use numpy.unique

import pandas as pd
import numpy as np

np.unique(salesdata.Outlet_Size.dropna().values)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM