会遇到dataframe中单元格既不是nan 又不是None 的 比如这种
created_at | catefirst |
2020-04-01 |
取得这种catefirst为空的需要用到
pd[(pd['catefirst'] == "")]
这时候能把空值找出
如果是对这一列来操作的话 处理空值 填充为0 或者别的 可以用map函数
#只对为空的或者为None的单元格替换为“无” 其余有正常值的保持不变
def catefirstmap(x):
if x=="" or x==None:
return "无"
else:
return x
然后通过map对列调用上面的函数
pd['catefirst']=pd['catefirst'].map(catefirstmap)