我正在尝试更改dataframe打印输出,以便它开始将第一个dataframe条目编号为40,而不是0
import pandas as pd
import numpy as np
import glob
import datetime as dt
import math
principle = 50000 # Amount initially invested
rate_of_return = .076 # Return on investment or the interest rate
years = 26 # Assuming starting at age 40 and end at age 65
roi_list = []
for i in range(years):
roi_list.append(principle)
principle = principle*(math.exp(rate_of_return))
df = pd.DataFrame(roi_list) # Creates a dataframe containing the roi_list values
print(df)
pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)采用
index
参数来提供索引信息这样就可以了:
因为您使用的是pandas,所以您可能需要考虑一个矢量化的解决方案。这就是熊猫的设计目的
演练:
years = np.arange(26)
创建一个从0开始到25结束的NumPy数组r
是我们的年化增长率。你在评论中说你假设的是指数增长率,但事实似乎并非如此。你目前使用的年化增长率e提高到.076(math.exp(r)
),年化增长率为7.89%。这是一个恒定的增长率,而不是指数增长率李>principle * ((1+r)**years)
。仅仅拿(1+r)**years
就可以显示出1美元的年复合增长率为7.6%。将(整个数组)乘以你的开始原则,得到该原则的假设增长李>相关问题 更多 >
编程相关推荐