DataFrame中将空字符串替换为NaN

Replacing blank values (white space) with NaN in pandas

df0 = df0.applymap(lambda x: np.NaN if str(x).isspace() else x) 
print("各列缺失行数为")
print(df0.isnull().sum())
print("各列未缺失行数为")
print(df0.notnull().sum())

参考链接

https://stackoverflow.com/questions/13445241/replacing-blank-values-white-space-with-nan-in-pandas

https://blog.csdn.net/th_num/article/details/80433373

发布了110 篇原创文章 · 获赞 18 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/momo_mo520/article/details/102543026