I have the following data frames.
df_1:
order_id date
123 2020-01-01
456 NaT
789 2020-10-10
135 2020-05-31
234 NaT
111 NaT
df_2:
order_id date
123 2020-01-02
456 2021-01-01
789 2020-10-11
135 2020-6-01
The output should capture anytime the date changes to a date in the future from the previous entry and/or when NaT changes to a new date.
new_df should equal:
order_id date
123 2020-01-02
456 2021-01-01
789 2020-10-11
135 2020-6-01
What I have tried:
df_1['date'] = pd.to_datetime(
df_1['date'])
df_2['date'] = pd.to_datetime(
df_2['date'])
s = df_2.set_index('order_id')['date']
mapped = df_1['order_id'].map(s)
mask = mapped > df_1['date']
df_1.loc[mask, 'date'] = mapped
This is only giving changes when the date is changed to a future date but it is not capturing anytime NaT becomes a new date.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…