I want to create a new boolean column that has a 0/1 depending if the ts_booking_at is null or not.
Currently I'm using the following code:
contacts.iloc[contacts["ts_accepted_at"] is np.nan, "accept"] = False
contacts.iloc[contacts["ts_accepted_at"] is not np.nan, "accept"] = True
But the following error returns
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

locnotilocto select the column by label more information here. You can't useisto test if something is NaN in pandas sinceisis going to assess if the Series itself (contacts["ts_accepted_at"]) isnp.nannot each value in the Series more details here. To check for NaN you can useisna/isnullas outlined here or the inversenotna/notnullcontacts.loc[contacts["ts_accepted_at"].isna(), "accept"] = Falseandcontacts.loc[contacts["ts_accepted_at"].notna(), "accept"] = Truecontacts['accept'] = contacts["ts_accepted_at"].notna()