小编San*_*jay的帖子

基于增长率优化值的迭代计算

这是我的数据帧:

Date              A          new_growth_rate
2011/01/01      100             
2011/02/01      101             
.
2012/01/01      120            0.035
2012/02/01      121            0.035
.
2013/01/01      131            0.036
2013/01/01      133            0.038
Run Code Online (Sandbox Code Playgroud)

这就是我需要的:

Date              A          new_growth_rate
2011/01/01      100             
2011/02/01      101             
.
.
2012/01/01      103.62          .035   A=100/(1-0.035)
2012/02/01      104.66          .035   A=101/(1-0.035)
.
.
2013/01/01     107.49           .036   A=103.62/(1-0.036)
2013/02/01     108.68           .038   A=104.66/(1-0.038)
Run Code Online (Sandbox Code Playgroud)

我需要根据每列的增长率计算价值我有一个400列的数据框及其相应的增长率.

我用以下公式计算了增长率:(one year old value)*(1+current month growth rate).此计算值将用于获取明年的值等等.像这样,我有400列及其相应的增长率.时间序列有30年的数据

目前我使用2 for循环1获取每列,然后第二次迭代每列的时间段并获得在之前for循环中计算的值.超过500行和400列数据集需要几个小时.还有更好的方法吗?`

我的代码段如下:

grpby = dataframe中的列列表

df_new=pd.DataFrame()
for i,row in grpby.iterrows():
    df_csr=grwth.loc[(grwth['A']==row['A'])].copy()
        a = pd.to_datetime("2011-12-01",format='%Y-%m-%d')
        b = a
        while b …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

6
推荐指数
1
解决办法
104
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1