熊猫 - 累积计算组
我正在尝试使用Jupyter笔记本中使用Pandas进行累积操作进行计算。
但是我卡住了。
我有以下数据框架:
日期 | 类型 | 存款 | 提款 |
---|---|---|---|
2020/01/19 | A | 1000 | 0 |
2020/01/23 | A | 500 | 0 |
2020/02/05 | A | 0 | 200 |
2020/02/22 | A | 1000 | 200 |
2020/01/19 | B | 859.8 | 0 0 |
2020/02/04 | B | 514.33 | 50 |
2020/02/25 | b | 1463.14 | 0 |
我需要应用此公式,按类型进行分组:
Movement = IF(ISNULL([previous_date]); [Current_Deposit] - [withdrawal];([previous_movement] * (1 +([current_date]-[previous_date]) * 0,0001)) + [Current_Deposit] - [withdrawal])
示例:
日期 | 类型的 | 存款 | 戒断 | 戒烟 | 公式 |
---|---|---|---|---|---|
2020/01/1000 | a | 1000 | 0 | 1000 | if(isnull(isnull)(iSnull) ); [1000] - [0];([0] *(1 +([2020/01/19] - [null]) * 0,0001)) + [1000] - [1000] - [0] |
) /23 | a | 500 | 0 | 1500.40 | if(isnull([2020/01/19])); [500] - [0];([1000] *(1 +([2020/01/23]) - [2020/01/19 ]) * 0,0001)) + [500] - [0]) |
2020/02/05 | a | 0 | 200 | 1302.35 | 如果(isnull([2020/01/23])); [0] - [0] - [200];([1500.40) ] *(1 +([2020/02/05] - [2020/01/23]) * 0,0001)) + [0] - [200] |
2020/02/22 | A | 1000 | 200 | 2104,56 | ) isnull([2020/02/05]); [1000] - [200];([1302.35] *(1 +([2020/02/22] + [1000] - [200]) |
2020/01/19 | B | 859.8 | 0 | 859.80 | if(isnull([Null]); [859.8] - [0] - [0];([0] *(1 +([2020/01/19) ] - [null]) * 0,0001)) + [859.8] - [0]) |
2020/02/04 | B | 514.33 | 50 | 1325.51 | if(isnull([2020/01/19]); [514.33] - [50];([[859.80] *(1 +([2020/02/04] - [2020/01/19]) * 0,0001)) + [514.33] - [50] - [50]) |
2020/) 02/25 | B | 1463.14 | 0 | 2791.43 | 如果(ISNULL([[2020/02/04])); [1463.14] - [0] - [0];([1325.51] *([1 +([2020/02/25]) - 04]) * 0,0001)) + [1463.14] - [0]) |
我无法累积要放入公式中的值。
我需要按类型对计算进行分组,并累积在当前行中使用的值。 我是Python的新手,我无法实施它。
I'm trying to do a calculation with cumulative operations using pandas in jupyter notebook.
But I'm stuck.
I have the following DataFrame:
Date | Type | deposit | withdrawal |
---|---|---|---|
2020/01/19 | A | 1000 | 0 |
2020/01/23 | A | 500 | 0 |
2020/02/05 | A | 0 | 200 |
2020/02/22 | A | 1000 | 200 |
2020/01/19 | B | 859.8 | 0 |
2020/02/04 | B | 514.33 | 50 |
2020/02/25 | B | 1463.14 | 0 |
I need to apply this formula, grouping by type:
Movement = IF(ISNULL([previous_date]); [Current_Deposit] - [withdrawal];([previous_movement] * (1 +([current_date]-[previous_date]) * 0,0001)) + [Current_Deposit] - [withdrawal])
Example:
Date | Type | deposit | withdrawal | Movement | Formula |
---|---|---|---|---|---|
2020/01/19 | A | 1000 | 0 | 1000 | IF(ISNULL([NULL]); [1000] - [0];([0] * (1 +([2020/01/19]-[NULL]) * 0,0001)) + [1000] - [0]) |
2020/01/23 | A | 500 | 0 | 1500.40 | IF(ISNULL([2020/01/19]); [500] - [0];([1000] * (1 +([2020/01/23]-[2020/01/19]) * 0,0001)) + [500] - [0]) |
2020/02/05 | A | 0 | 200 | 1302.35 | IF(ISNULL([2020/01/23]); [0] - [200];([1500.40] * (1 +([2020/02/05]-[2020/01/23]) * 0,0001)) + [0] - [200]) |
2020/02/22 | A | 1000 | 200 | 2104,56 | IF(ISNULL([2020/02/05]); [1000] - [200];([1302.35] * (1 +([2020/02/22]-[2020/02/05]) * 0,0001)) + [1000] - [200]) |
2020/01/19 | B | 859.8 | 0 | 859.80 | IF(ISNULL([NULL]); [859.8] - [0];([0] * (1 +([2020/01/19]-[NULL]) * 0,0001)) + [859.8] - [0]) |
2020/02/04 | B | 514.33 | 50 | 1325.51 | IF(ISNULL([2020/01/19]); [514.33] - [50];([859.80] * (1 +([2020/02/04]-[2020/01/19]) * 0,0001)) + [514.33] - [50]) |
2020/02/25 | B | 1463.14 | 0 | 2791.43 | IF(ISNULL([2020/02/04]); [1463.14] - [0];([1325.51] * (1 +([2020/02/25]-[2020/02/04]) * 0,0001)) + [1463.14] - [0]) |
I'm not able to accumulate the values to put in the formula.
I need to group the calculations by type, and accumulate the values to use in the current line.
I'm new to python and I'm not able to implement it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的数据帧按类型和日期进行排序
输出
I assume that your dataframe is sorted by Type and Date
OUTPUT