0

I'm loading a excel file with pandas and iterating it's rows checking if the 'Status' Column is not NULL and I'm getting an error AttributeError: 'str' object has no attribute 'isnull', I also tried isna(), is None.

Code:

data = read_excel('ExcelFile.xlsx')
results = {

}
for index, row in data.iterrows():
    if row['Status'].isnull():
        print('NULL')

DataFrame:

   ID   Status
0   0  Success
1   1      NaN
  • 4
    You're not supposed to iterate over dataframes. Use boolean indexing instead, e.g., `data[data['Status'].isnull()]` to select all rows where the status is null (see [this answer](https://stackoverflow.com/a/55557758/15873043)). – fsimonjetz Dec 14 '22 at 17:18

1 Answers1

1

Check the type of the 'Status' column, probably it is a object (str). And str object doesn't have isnull() method. Give a try:

data = read_excel('ExcelFile.xlsx')
results = {

}
for index, row in data.iterrows():
    if row['Status'] == 'NaN':
        print('NULL')

You can check the column's type, with data.info()