zl程序教程

您现在的位置是:首页 >  Python

当前栏目

PYTHON 判断 空值的方法

2023-04-18 14:43:12 时间

1、数值类型空值判断:
if not math.isnan(p[‘百度纬度’]):
2、字符类型判断空值
if xxx
None,’’,0,[],{},() ,False都被判断为空值(not xxx等价)
如下代码输出所示,

if xxx is None
需要区分[],{},‘’,()等空值对象与None的区别时时可使用这种写法

3、shaply判断
selectall = selectall[~selectall.conband.is_empty]

4、pandas 自动填充
只能单列填充none值
cphon[‘百度经度’].fillna(‘无经纬度’,inplace=True)
cphon[‘百度纬度’].fillna(‘无经纬度’,inplace=True)

cphon[‘百度边框’] = cphon[‘百度边框’].apply(lambda x: ‘无经百度边框’ if str(x) == ‘nan’ else x)