I have a dataframe which looks something like this:
id ts factor
A 2020-01-01 1
A 2020-01-02 1
A 2020-01-03 1
A 2020-01-04 1
A 2020-01-05 1
A 2020-01-06 10
A 2020-01-07 10
A 2020-01-08 10
A 2020-01-09 10
A 2020-01-10 10
A 2020-01-11 10
A 2020-01-12 10
A 2020-01-13 10
A 2020-01-14 10
A 2020-01-15 10
A 2020-01-16 10
A 2020-01-17 10
A 2020-01-18 1
A 2020-01-19 1
A 2020-01-20 1
my desire output is:
id start_ts end_ts factor
A 2020-01-01 2020-01-05 1
A 2020-01-06 2020-01-17 10
A 2020-01-18 2020-01-20 1
so far I can only think of groupby on factor and then do min and max operation, but that doesn't work for factor 1
df.groupby(["factor"]).agg({'date' : [np.min, np.max]})
how can I achieve the output?