I am trying to decrease by 2.5% the value of all records that are higher than the mean in my pandas series.
I would like to solve the problem using the update method
price_per_city = {
"Bragança": 10.3,
"Braga": 10.6,
"Porto": 11.5,
"Aveiro": 12.3,
"Coimbra": 9.9,
"Leiria": 9.3,
"Lisboa": 12.1,
"Beja": 10.9,
"Évora": 11.4,
"Faro": 9.1
}
prcSerie = pd.Series(price_per_city)
prcSerie.update(prcSerie, prcSerie[prcSerie >=prcSerie.mean()])
print(prcSerie)
>Solution :
Using update for in place modification:
prcSerie.update(prcSerie.loc[prcSerie>=prcSerie.mean()].mul(0.975).round(2))
Output:
Bragança 10.30
Braga 10.60
Porto 11.21
Aveiro 11.99
Coimbra 9.90
Leiria 9.30
Lisboa 11.80
Beja 10.63
Évora 11.12
Faro 9.10
dtype: float64