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 nu
Problem is you need compare scalar for return scalar (True, False), but there is one item Series, which is converted to one item boolean Series.
Solutions is converting to scalar using Series.item or values with selecting first value by [0]:
customer_ID = '8143511'
ts = '2012-07-01 00:00:00'
print (df[[customer_ID]].loc[ts].item())
nan
if pd.isnull(df[[customer_ID]].loc[ts]).item():
print ('super')
print (df[[customer_ID]].loc[ts].values[0])
nan
if pd.isnull(df[[customer_ID]].loc[ts]).values[0]:
print ('super')
But if use DataFrame.loc, get scalar (if not duplicated index or columns names):
print (df.loc[ts, customer_ID])
nan
customer_ID = '8143511'
ts = '2012-07-01 00:00:00'
if pd.isnull(df.loc[ts, customer_ID]):
print ('super')