I'm running a query in a dataframe to retrieve a column value whenever a condition is met. For instance, I want to get col1
whenever col2=0
.
result = df['col1'].loc[df['col2']==0]
Next, I want to check that
- The results are not empty, i.e. there is at least one instance where
col2=0
- The returned value of
col1
is not NaN
So I write:
if not result.empty and not result.isnull():
pass
But this raises:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What am I actually supposed to do?