我有一个 pandas 数据框的列,这个列是从数据库查询中获取的,其中包含空白单元格。空白单元格会变成 "None",我想检查每一行是否为 None:
我遇到了以下错误:
我最终能够使用
In [325]: yes_records_sample['name']
Out[325]:
41055 John J Murphy Professional Building
25260 None
41757 Armand Bayou Nature Center
31397 None
33104 Hubert Humphrey Building
16891 Williams Hall
29618 None
3770 Covenant House
39618 None
1342 Bhathal Student Services Building
20506 None
根据文档的理解,我可以使用isnull()
命令检查每一行是否为空 http://pandas.pydata.org/pandas-docs/dev/missing_data.html#values-considered-missing
然而,这个函数对我来说没有起作用:
In [332]: isnull(yes_records_sample['name'])
我遇到了以下错误:
NameError Traceback (most recent call last)
<ipython-input-332-55873906e7e6> in <module>()
----> 1 isnull(yes_records_sample['name'])
NameError: name 'isnull' is not defined
我也看到有人只是替换了"None"字符串,但这些方法都对我不起作用: 在Pandas中重命名"None"值
yes_records_sample['name'].replace('None', "--no value--")
yes_records_sample['name'].replace(None, "--no value--")
我最终能够使用
fillna
函数,并将这些行填充为空字符串yes_records_sample.fillna('')
作为解决方法,然后我可以检查yes_records_sample['name']==''
。但是我对'None'的工作原理和含义感到深深困惑。是否有一种简单的方法只检查数据框中的单元格是否为'None'?
nbs_annot['pathogenic'] = (nbs_annot['impact'] == 'HIGH') | ~nbs_annot['clin_acc'].isnull()
- SummerEla