Same question as here: group by pandas dataframe and select latest in each group, except instead of latest date, would like to get next upcoming date for each group.
So given a dataframe sorted by date:
id product date
0 220 6647 2020-09-01
1 220 6647 2020-10-03
2 220 6647 2020-12-16
3 826 3380 2020-11-11
4 826 3380 2020-12-09
5 826 3380 2021-05-19
6 901 4555 2020-09-01
7 901 4555 2020-12-01
8 901 4555 2021-11-01
Using todays date (2020-12-01) to determine the next upcoming date, grouping by id or product and selecting the the next upcoming date should give:
id product date
2 220 6647 2020-12-16
5 826 3380 2020-12-09
8 901 4555 2021-11-01