基本信息
源码名称:知乎数据清洗整理和结论研究
源码大小:2.30M
文件格式:.zip
开发语言:Python
更新时间:2021-02-22
   源码介绍

知乎数据清洗整理和结论研究

# 数据清洗 - 去除空值 
# 要求:创建函数
# 提示:fillna方法填充缺失数据,注意inplace参数

def data_cleaning(df):
    cols = df.columns
    for col in cols:
        if df[col].dtype ==  'object':
            df[col].fillna('缺失数据', inplace = True)
        else:
            df[col].fillna(0, inplace = True)
    return(df)
# 该函数可以将任意数据内空值替换

data1_c = data_cleaning(data1)
data1_c.head(10)