I need help with groupby in pandas:
I have following df:
A B C D
04547 2022-07-04 2022-07-04 1000000
04547 2022-07-11 2022-07-11 1000000
04547 2022-08-08 2022-08-08 1000000
04547 2022-10-11 2022-10-11 0100000
04547 2022-10-18 2022-10-18 0100000
04547 2022-10-24 2022-10-24 1000000
04547 2022-11-01 2022-11-01 0100000
04547 2022-11-08 2022-11-08 0100000
04548 2022-10-11 2022-10-11 0100000
04548 2022-10-18 2022-10-18 0100000
04548 2022-10-24 2022-10-24 1000000
04548 2022-11-01 2022-11-01 0100000
04548 2022-11-08 2022-11-08 0100000
my needed output should be:
A B C D
04547 2022-07-04 2022-08-08 1000000
04547 2022-10-11 2022-10-18 0100000
04547 2022-10-24 2022-10-24 1000000
04547 2022-11-01 2022-11-08 0100000
04548 2022-10-11 2022-10-18 0100000
04548 2022-10-24 2022-10-24 1000000
04548 2022-11-01 2022-11-08 0100000
but with:
a = {'A':'first','B':'first','C':'last','D':'first'}
df = df.groupby(['A','D']).agg(a)
A B C D
4547 2022-10-11 2022-11-08 0100000
4547 2022-07-04 2022-10-24 1000000
4548 2022-10-11 2022-11-08 0100000
4548 2022-10-24 2022-10-24 1000000
because I have to interrupt grouping when a new series in column D starts seperated for each column A