studf = pd.read_excel("datas/student_excel/student_excel.xlsx",skiprows=2)
# print(studf)
# 检测空值
# print(studf.isnull())
# print(studf["分数"].isnull())
# print(studf["分数"].notnull())
# print(studf.loc[studf["分数"].notnull(),:])
# 删除掉全是空值的列
studf.dropna(axis="columns",how='all',inplace=True)
# print(studf)
# 删除掉全是空值的行
studf.dropna(axis="index",how='all',inplace=True)
# print(studf)
# print(studf.fillna({"分数": 0}))
studf.loc[:,'分数'] = studf['分数'].fillna(0) #与上一行相同
# print(studf)
studf.loc[:,'姓名'] = studf['姓名'].fillna(method='ffill')
# print(studf)
studf.to_excel("datas/student_excel/student_excel_clean.xlsx",index=False)
Pandas对缺失值的处理
最新推荐文章于 2025-02-25 15:22:32 发布