Hello Community,
in my dataframe i have three columns as follow:
restaurant_id, annee, moyenne_etoile_annee.
for each restaurant_id i would like to substract the "moyenne_etoiles_annee' of the last year minus the one from the first year.
By example for the first restaurant_id df[diff]=moyenne_etoiles_annee(2017)-moyenne_etoiles_annee(2015) 2-2.66=-0.66
I tried to .agg and select first and last value but wasn't able to execute properly.
Sample:
df = pd.DataFrame({"restaurant_id": [1,1,2,2],
"annee": [2015,2016,2019,2022],
"moyenne_etoile_annee": [1.2,1.4,1.3,1.3]})