I need the row number of a matching cell that is empty: Int64Index([], dtype='int64'). I am receiving an index 0 is out of bounds for axis 0 with size 0 exception.
Print indices of matching elements:
if len(item) < 9:
print(item)
print(df[df['column name'] == item].index)
Output:
nan
1234
abc
Int64Index([], dtype='int64')
Int64Index([209], dtype='int64')
Int64Index([325], dtype='int64')
Print indice number of matching cells:
print(df[df['column name'] == item].index[0])
Output, empty indice throws exception:
index 0 is out of bounds for axis 0 with size 0
Output without blank cell:
208
324
Thanks!
df[df['column name'] == nan], that filtering is returning an empty dataframe. That is, nothing in the original dataframe has nan as the value there. Then you are trying to print the a row from an empty dataframe, there is nothing to print. You probably want to 1) check if you should be getting nothing from the filter, and/or 2) add atry:...except:...for when the filter returns nothing at all