I have a column with dates, and I want to apply a conditional lambda function, which gives the value one to the 'Type' column in case the values are NaTs. I'm having a lot of problems detecting these NaTs.
With unique I get the empty values, and it tells me that they are NaT
df['fechaActivacion'].unique()
The result is as follows:
array([ 'NaT', '2022-08-02T15:27:28.000000000', '2022-07-09T21:10:03.000000000', ..., '2022-06-27T17:17:50.000000000', '2022- 08-10T21:56:10.000000000', '2022-08-23T17:53:08.000000000'], dtype='datetime64[ns]')
I have tried the following:
df['type'] = df['fechaActivacion'].apply(lambda x: 1 if x == pd.NaT else 0)
I don't get any errors, but all the values are generated as 0, when there are NaT values and 1's should have been generated as well.
Thanks in advance!
According to the documentation , the function should be used
isna
, instead of a normal comparison, to check if a value is missing .Or better yet: