I have a dataframe storing a date, car_brand, color and a city:
date car_brand color city
"2020-01-01" porsche red paris
"2020-01-02" prosche red paris
"2020-01-03" porsche red london
"2020-01-04" porsche red paris
"2020-01-05" porsche red london
"2020-01-01" audi blue munich
"2020-01-02" audi red munich
"2020-01-03" audi red london
"2020-01-04" audi red london
"2020-01-05" audi red london
I now want to create from that a dataframe in the following way:
Merge rows together where for consecutive days the car_brand, color and city match. So in the example I want to end up with a dataframe
date car_brand color city
["2020-01-01","2020-01-02"] porsche red paris
["2020-01-03"] porsche red london
["2020-01-04"] porsche red paris
["2020-01-05"] porsche red london
["2020-01-01"] audi blue munich
["2020-01-02"] audi red munich
["2020-01-03","2020-01-05"] audi red london
How can I achieve that? I tried with pd.concat and pd.merge but nothing worked so far. Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…