I am getting the error when I make a comparison on a single element in a dataframe, but I don't understand why.
I have a dataframe df with timeseries data for a number of customers, with some null values within it:
df.head()
8143511 8145987 8145997 8146001 8146235 8147611 \
2012-07-01 00:00:00 NaN NaN NaN NaN NaN NaN
2012-07-01 00:30:00 0.089 NaN 0.281 0.126 0.190 0.500
2012-07-01 01:00:00 0.090 NaN 0.323 0.141 0.135 0.453
2012-07-01 01:30:00 0.061 NaN 0.278 0.097 0.093 0.424
2012-07-01 02:00:00 0.052 NaN 0.278 0.158 0.170 0.462
In my script, the line
if pd.isnull(df[[customer_ID]].loc[ts]):
generates an error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
However, if I put a breakpoint on the line of script, and when the script stops I type this into the console:
pd.isnull(df[[customer_ID]].loc[ts])
the output is:
8143511 True
Name: 2012-07-01 00:00:00, dtype: bool
If I allow the script to continue from that point, the error is generated immediately.
If the boolean expression can be evaluated and has the value True, why does it generate an error in the if expression? This makes no sense to me.