我正在使用 pandas 加载 Excel 文件并迭代它的行,检查“状态”列是否不为 NULL,并且我收到错误
AttributeError: 'str' object has no attribute 'isnull'
,我也尝试了isna(), is None
。
代码:
data = read_excel('ExcelFile.xlsx')
results = {
}
for index, row in data.iterrows():
if row['Status'].isnull():
print('NULL')
数据框:
ID Status
0 0 Success
1 1 NaN
检查“Status”列的类型,可能是一个对象(str)。并且 str 对象没有 isnull() 方法。尝试一下:
data = read_excel('ExcelFile.xlsx')
results = {
}
for index, row in data.iterrows():
if row['Status'] == 'NaN':
print('NULL')
您可以使用 data.info() 检查列的类型
使用 pd.isnull()
data = read_excel('ExcelFile.xlsx')
results = {
}
for index, row in data.iterrows():
if pd.isnull(row['Status']):
print('NULL')