python - 如何在 Pandas 的预算表中添加一列增长率?

标签 python pandas jupyter-notebook

我想知道如何在 Pandas 的以下数据中添加逐年增长率。

    Date  Total Managed Expenditure
0   2001                      503.2
1   2002                      529.9
2   2003                      559.8
3   2004                      593.2
4   2005                      629.5
5   2006                      652.1
6   2007                      664.3
7   2008                      688.2
8   2009                      732.0
9   2010                      759.2
10  2011                      769.2
11  2012                      759.8
12  2013                      760.6
13  2014                      753.3
14  2015                      757.6
15  2016                      753.9

最佳答案

使用系列.pct_change() :

df['Total Managed Expenditure'].pct_change()
Out: 
0          NaN
1     0.053060
2     0.056426
3     0.059664
4     0.061194
5     0.035902
6     0.018709
7     0.035978
8     0.063644
9     0.037158
10    0.013172
11   -0.012220
12    0.001053
13   -0.009598
14    0.005708
15   -0.004884
Name: Total Managed Expenditure, dtype: float64

将其分配回去:

df['Growth Rate'] = df['Total Managed Expenditure'].pct_change()

关于python - 如何在 Pandas 的预算表中添加一列增长率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43709200/

相关文章:

python-3.x - 如何从 Pandas 字符串中提取前8个字符

python - 如何在不使用选项卡的情况下在 jupyter notebook 中获得自动完成功能?

python - 4.1.1版本之后如何登录Jupyter笔记本的控制台而不是网页

python - GEMM 使用 Numpy einsum

python - 为什么在 python 队列消耗完所有工作后不释放线程

pandas - 生成具有条件的随机数列表 - numpy

python - 在 xlabel 上绘制带有总行和日期的堆积条形图

python - IPython 细胞魔法?

python - Pandas - Groupby 或将多个数据帧剪切到垃圾箱

python - 如何对 pandas 数据框进行非规范化