我試圖將所有高于我的熊貓系列中平均值的記錄的值降低 2.5%。
我想使用更新方法解決問題
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)
uj5u.com熱心網友回復:
嘗試where:
prcSerie = prcSerie.where(prcSerie.le(prcSerie.mean()), prcSerie.mul(0.975))
>>> prcSerie
Bragan?a 10.3000
Braga 10.6000
Porto 11.2125
Aveiro 11.9925
Coimbra 9.9000
Leiria 9.3000
Lisboa 11.7975
Beja 10.6275
évora 11.1150
Faro 9.1000
dtype: float64
uj5u.com熱心網友回復:
使用updatefor 就地修改:
prcSerie.update(prcSerie.loc[prcSerie>=prcSerie.mean()].mul(0.975).round(2))
輸出:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/441373.html
