[英]Pandas calculation within a dataframe
Have a simple pandas dataframe like that:有一个像这样的简单熊猫数据框:
period count
0 4000
1 20000
How can I perform calcualtion 4000/(4000+20000) using pandas syntax and this dataframe?如何使用 Pandas 语法和此数据框执行 4000/(4000+20000) 计算?
You can use the rolling
method to sum and then divide.您可以使用
rolling
方法求和然后除法。
df['count'].rolling(2).apply(lambda x: x[0] / x.sum()).dropna()
1 0.166667
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.