I have below dataframe df, where stamp B are null sometimes. Have to fill such null values with date of Stamp A and respective time from the Time column
stamp A stamp B Time
0 2012-10-08 18:15:05 2012-10-08 18:15:05 19:00:01
1 2012-10-09 12:15:05 NaT 18:45:09
2 2012-10-11 18:13:00 NaT 12:20:20
3 2012-10-11 08:15:15 2012-10-11 18:15:05 22:10:05
4 2012-10-12 18:15:20 2012-10-12 17:10:20 19:34:12
Here is my solution -
>>>from datetime import dateime as dtm
>>>result = df[df['stamp B'].isnull()].apply(lambda x: dtm.combine(x['stamp A'].date(), dtm.strptime(x["Time"], "%H:%M:%S").time()), axis=1)
It returns result as below:
1 2012-10-09 18:45:09
2 2012-10-11 12:20:20
dtype: datetime64[ns]
But not sure, how to replace this result withNaT values in the original dataframe df['stamp B']