我有不平衡的面板。基本上,有人会在完全减少流动性之前增加流动性。我有组(NF_TOKEN_ID)。我想先groupby
,每当ACTION
是DECREASE_LIQUIDITY
时,我想用所有已提取的资金替换零值。该量对应于先前添加的量。因此,如果ACTION
的值是INCREASE_LIQUIDITY
,则必须对以前的值进行cumsum。cumsum
只适用于之前添加的资金,而不是追溯。
我现在的DF
BLOCK_TIMESTAMP NF_TOKEN_ID ACTION LIQUIDITY AMOUNT0_ADJUSTED AMOUNT1_ADJUSTED
0 2023-01-19 11:43:23+00:00 417467.0 INCREASE_LIQUIDITY 2.0002500037479372e+16 0.0 999999.999999
1 2023-01-21 10:08:35+00:00 417467.0 DECREASE_LIQUIDITY 2.0002500037479372e+16 0.0 0.0
2 2023-01-23 17:43:23+00:00 417467.0 INCREASE_LIQUIDITY 1.9999500037496876e+16 1000000.0 0.0
3 2023-01-28 21:42:47+00:00 417467.0 DECREASE_LIQUIDITY 1.9999500037496876e+16 0.0 0.0
4 2023-01-31 09:20:11+00:00 417467.0 INCREASE_LIQUIDITY 2.001358136187257e+16 0.0 1000553.996968
5 2023-02-05 14:19:11+00:00 417467.0 DECREASE_LIQUIDITY 2.001358136187257e+16 0.0 0.0
6 2023-02-06 16:00:59+00:00 417467.0 INCREASE_LIQUIDITY 3.9510177985927736e+16 900000.0 1075372.476351
7 2023-02-11 16:21:47+00:00 417467.0 DECREASE_LIQUIDITY 3.9510177985927736e+16 0.0 0.0
8 2023-02-11 18:17:47+00:00 417467.0 INCREASE_LIQUIDITY 3.999900007499375e+16 2000000.0 0.0
9 2023-02-13 08:42:47+00:00 417467.0 DECREASE_LIQUIDITY 3.999900007499375e+16 0.0 0.0
10 2023-02-16 23:39:11+00:00 417467.0 INCREASE_LIQUIDITY 6.000384593243181e+16 3000267.297679 0.0
11 2023-02-18 13:02:47+00:00 417467.0 INCREASE_LIQUIDITY 2.000210525110979e+16 1000130.263937 0.0
64 2023-01-19 11:52:47+00:00 417520.0 INCREASE_LIQUIDITY 1.5233876511464717e+21 2360900.644245 17981.537918728
65 2023-01-19 11:52:47+00:00 417520.0 DECREASE_LIQUIDITY 1.5233876511464717e+21 0.0 0.0
66 2023-01-19 11:52:59+00:00 417521.0 INCREASE_LIQUIDITY 1e+19 0.05981737761 0.05981737761
81 2023-01-19 11:54:35+00:00 417537.0 INCREASE_LIQUIDITY 17130998133876.0 49.99712 0.02400335355
82 2023-01-23 07:29:23+00:00 417537.0 INCREASE_LIQUIDITY 28028281686564.0 121.373999 0.01412890286
83 2023-01-23 17:34:35+00:00 417537.0 INCREASE_LIQUIDITY 9508091561328.0 39.513265 0.00581565507
84 2023-01-25 00:55:47+00:00 417537.0 DECREASE_LIQUIDITY 54667371381768.0 0.0 0.0
所需df
BLOCK_TIMESTAMP NF_TOKEN_ID ACTION LIQUIDITY AMOUNT0_ADJUSTED AMOUNT1_ADJUSTED
0 2023-01-19 11:43:23+00:00 417467.0 INCREASE_LIQUIDITY 2.0002500037479372e+16 0.0 999999.999999
1 2023-01-21 10:08:35+00:00 417467.0 DECREASE_LIQUIDITY 2.0002500037479372e+16 0.0 999999.999999
2 2023-01-23 17:43:23+00:00 417467.0 INCREASE_LIQUIDITY 1.9999500037496876e+16 1000000.0 0.0
3 2023-01-28 21:42:47+00:00 417467.0 DECREASE_LIQUIDITY 1.9999500037496876e+16 1000000.0 0.0
4 2023-01-31 09:20:11+00:00 417467.0 INCREASE_LIQUIDITY 2.001358136187257e+16 0.0 1000553.996968
5 2023-02-05 14:19:11+00:00 417467.0 DECREASE_LIQUIDITY 2.001358136187257e+16 0.0 1000553.996968
6 2023-02-06 16:00:59+00:00 417467.0 INCREASE_LIQUIDITY 3.9510177985927736e+16 900000.0 1075372.476351
7 2023-02-11 16:21:47+00:00 417467.0 DECREASE_LIQUIDITY 3.9510177985927736e+16 900000.0 1075372.476351
8 2023-02-11 18:17:47+00:00 417467.0 INCREASE_LIQUIDITY 3.999900007499375e+16 2000000.0 0.0
9 2023-02-13 08:42:47+00:00 417467.0 DECREASE_LIQUIDITY 3.999900007499375e+16 2000000.0 0.0
10 2023-02-16 23:39:11+00:00 417467.0 INCREASE_LIQUIDITY 6.000384593243181e+16 3000267.297679 0.0
11 2023-02-18 13:02:47+00:00 417467.0 INCREASE_LIQUIDITY 2.000210525110979e+16 1000130.263937 0.0
64 2023-01-19 11:52:47+00:00 417520.0 INCREASE_LIQUIDITY 1.5233876511464717e+21 2360900.644245 17981.537918728
65 2023-01-19 11:52:47+00:00 417520.0 DECREASE_LIQUIDITY 1.5233876511464717e+21 2360900.644245 17981.537918728
66 2023-01-19 11:52:59+00:00 417521.0 INCREASE_LIQUIDITY 1e+19 0.05981737761 0.05981737761
81 2023-01-19 11:54:35+00:00 417537.0 INCREASE_LIQUIDITY 17130998133876.0 49.99712 0.02400335355
82 2023-01-23 07:29:23+00:00 417537.0 INCREASE_LIQUIDITY 28028281686564.0 121.373999 0.01412890286
83 2023-01-23 17:34:35+00:00 417537.0 INCREASE_LIQUIDITY 9508091561328.0 39.513265 0.00581565507
84 2023-01-25 00:55:47+00:00 417537.0 DECREASE_LIQUIDITY 54667371381768.0 210.884384 0.04394791148
1条答案
按热度按时间w8ntj3qf1#
IIUC,您可以用途:
输出:
编辑
当ACTION为DECREASE_LIQUIDITY时,如何将值设置为负值?