I've been trying various codes for a while but I can't get what I need. The initial data frame is:
Number Date 1 Date 2
1 2020/04/20 2021/03/04
2 2020/04/20 2021/03/04
3 2020/04/20 2021/03/04
1 2020/05/26 2021/08/04
2 2020/05/26 2021/08/04
3 2020/05/26 2021/08/04
When the number column is equal to 1, I want to mix the dates: take the year from date 1 and the month and day from date 2, and the rest of the empty rows.
What i would like to have:
Number Date 1 Date 2 Date 3
1 2020/04/20 2021/03/04 2020/03/04
2 2020/04/20 2021/03/04 0
3 2020/04/20 2021/03/04 0
1 2020/05/26 2021/08/04 2020/08/04
2 2020/05/26 2021/08/04 0
3 2020/05/26 2021/08/04 0
and in the empty spaces add one year to the previous date, thus:
Number Date 1 Date 2 Date 3
1 2020/04/20 2021/03/04 2020/03/04
2 2020/04/20 2021/03/04 2021/03/04
3 2020/04/20 2021/03/04 2022/03/04
1 2020/05/26 2021/08/04 2020/08/04
2 2020/05/26 2021/08/04 2021/08/04
3 2020/05/26 2021/08/04 2022/08/04
I have tried the following:
df['Date 3'] = (df['Number'] ==1, (df['Date 1'].dt.year) + (df['Date 2'].dt.month) + (df['Date '].dt.day), 0)
but add the days and that's what I don't want