我有一个数据框如下,
SP IS
group2
Control 669303.62 0.00
Test - NonRedeemers 1888366.53 -1219062.91
Test - Redeemers 709095.22 -39791.60
我需要计算差异变化的百分比,我想要使用的公式是(df['IS']/df.loc['Control'].iat[0])*100
我应用它但我需要绝对值的百分比。 非常感谢任何帮助
答案 0 :(得分:1)
似乎你需要:
a = ((df['IS']/df.loc['Control'].iat[0])*100).abs()
print (a)
group2
Control 0.000000
Test - NonRedeemers 182.138998
Test - Redeemers 5.945224
Name: IS, dtype: float64
a = df['IS'].div(df.loc['Control'].iat[0]).mul(100).abs()
print (a)
group2
Control 0.000000
Test - NonRedeemers 182.138998
Test - Redeemers 5.945224
Name: IS, dtype: float64