DATA
Division Name start_date
A apple 2001-01-05
A banana 2001-03-06
A apple 2001-06-08
A orange 2001-07-09
B peach 2001-01-10
B melon 2001-06-02
B berry 2001-08-19
I need to create an end_date, which is the start_date of the next person in the same division. For the last person observed, there is no end_date, so I would just put today's date 2019-04-06.
GOAL
Division Name start_date end_date
A apple 2001-01-05 2001-03-06
A banana 2001-03-06 2001-06-08
A apple 2001-06-08 2001-07-09
A orange 2001-07-09 2019-04-06
B peach 2001-01-10 2001-06-02
B melon 2001-06-02 2001-08-19
B berry 2001-08-19 2019-04-06
I tried
data['end_date'] = data.groupby('Division')['start_date'].index+1
But got an error message:
AttributeError: Cannot access attribute 'index' of 'SeriesGroupBy' objects, try using the 'apply' method
Does anyone know how to fix this?
Many thanks!