【发布时间】:2020-03-19 16:11:04
【问题描述】:
我有一个具有时间序列的 DataFrame。我需要获得第一行并添加喜欢我的投资。下一行是另一天,我需要比较以获取值差异,这将是我 1 天的累积值。
我的数据:
翻译: 数据 = 日期
Cota = 配额
Patrimonio Liquido = 净资产
目前我的代码如下所示:
len_fundo = len(self.fundo)
investiment = self.fundo.iloc[0]
dict_accumulated = {}
for value in range(1, len_fundo):
next_line = self.fundo.iloc[value]
dict_accumulated['Data'] = next_line['Data']
dict_accumulated['Acumulado'] = next_line['PL'] - investiment['PL']
investiment = next_line
accumulated = pd.DataFrame(data=dict_accumulated, index=[value])
return accumulated
但结果只有最后一行。
Data Acumulado
4 2019-12-06 942355.3
我知道这是因为 python dict 不接受重复键;因此,它取代了钥匙,但我该如何解决这种情况? 我需要为每一天生成一个包含日期和累计值列的新 DF...
结果将是一个像这样的新 DF:
【问题讨论】:
标签: python pandas dataframe dictionary time-series