【发布时间】:2020-10-24 15:57:03
【问题描述】:
# handling missing values
class handling_missing_data():
# Imputation
# Handling columns which have null values
for col in df[:]:
if ():
if (pd.df[:].astype(pd.Series([np.integer]))):
df = df.select_dtypes(include=[np.integer]).fillna(df.select_dtypes(include=[np.integer]).mean().iloc[0], inplace=True)
elif (pd.df[:].astype(pd.Series([object, str]))):
df = df.select_dtypes(include=['object', 'str']).fillna(df.select_dtypes(include=['object', 'str']).mode().iloc[0], inplace=True)
print(df.head())
为什么此代码不起作用,因为我试图识别特定列中数据集中的缺失值,并通过使用循环根据列数据类型使用平均值填充缺失的列值。我正在寻找一些通用的方法。
【问题讨论】:
标签: python pandas dataframe data-science