0

I am trying to replace an NaT value in a formatted datetime column with the date from another column.

I.e. if column [2] (Description_Date) shows NaT, return date in that column with the date in column [0] (PostingDate)

    PostingDate Day of Week Description_Date
0   2023-02-28  Tuesday               NaT   
0   2023-02-28  Tuesday               NaT   
0   2023-02-28  Tuesday               NaT   
0   2023-02-28  Tuesday               NaT   
0   2023-02-28  Tuesday               NaT   
5   2023-02-28  Tuesday            2023-02-24   
6   2023-02-28  Tuesday            2023-02-20

I have tried to used the following code to replace NaT with the value from PostingDate:

column:df['Description_Date'].replace('NaT', df.loc[df['PostingDate']])

I receive this error dtype='datetime64[ns]', length=499, freq=None)] are in the [index]

BVD
  • 1
  • `df['Description_Date'] = df['Description_Date'].fillna(PostingDate)`, ensure that you have real NaT (`df.replace({'NaT', np.nan})` if needed), but this should be the case given your dtype – mozway Mar 22 '23 at 12:20

0 Answers0