数据帧:如何在同一列中的2个相同的数字之间获得最小数字?
绝对容易通过一个示例显示:
{'Close': {Timestamp('1980-12-12 00:00:00'): 28.75, Timestamp('1980-12-15 00:00:00'): 27.25, Timestamp('1980-12-16 00:00:00'): 25.25, Timestamp('1980-12-17 00:00:00'): 25.87, Timestamp('1980-12-18 00:00:00'): 26.63, Timestamp('1980-12-19 00:00:00'): 28.25, Timestamp('1980-12-22 00:00:00'): 29.63, Timestamp('1980-12-23 00:00:00'): 30.88, Timestamp('1980-12-24 00:00:00'): 32.5, Timestamp('1980-12-26 00:00:00'): 35.5, Timestamp('1980-12-29 00:00:00'): 36.0, Timestamp('1980-12-30 00:00:00'): 35.12, Timestamp('1980-12-31 00:00:00'): 34.13, Timestamp('1981-01-02 00:00:00'): 34.5, Timestamp('1981-01-05 00:00:00'): 33.75, Timestamp('1981-01-06 00:00:00'): 32.25, Timestamp('1981-01-07 00:00:00'): 30.88, Timestamp('1981-01-08 00:00:00'): 30.25, Timestamp('1981-01-09 00:00:00'): 31.88, Timestamp('1981-01-12 00:00:00'): 31.62, Timestamp('1981-01-13 00:00:00'): 30.5, Timestamp('1981-01-14 00:00:00'): 30.63, Timestamp('1981-01-15 00:00:00'): 31.25, Timestamp('1981-01-16 00:00:00'): 31.0, Timestamp('1981-01-19 00:00:00'): 32.87, Timestamp('1981-01-20 00:00:00'): 31.88, Timestamp('1981-01-21 00:00:00'): 32.5, Timestamp('1981-01-22 00:00:00'): 32.87, Timestamp('1981-01-23 00:00:00'): 32.75, Timestamp('1981-01-26 00:00:00'): 32.25}, 'Roll_Max': {Timestamp('1980-12-12 00:00:00'): 28.75, Timestamp('1980-12-15 00:00:00'): 28.75, Timestamp('1980-12-16 00:00:00'): 28.75, Timestamp('1980-12-17 00:00:00'): 28.75, Timestamp('1980-12-18 00:00:00'): 28.75, Timestamp('1980-12-19 00:00:00'): 28.75, Timestamp('1980-12-22 00:00:00'): 29.63, Timestamp('1980-12-23 00:00:00'): 30.88, Timestamp('1980-12-24 00:00:00'): 32.5, Timestamp('1980-12-26 00:00:00'): 35.5, Timestamp('1980-12-29 00:00:00'): 36.0, Timestamp('1980-12-30 00:00:00'): 36.0, Timestamp('1980-12-31 00:00:00'): 36.0, Timestamp('1981-01-02 00:00:00'): 36.0, Timestamp('1981-01-05 00:00:00'): 36.0, Timestamp('1981-01-06 00:00:00'): 36.0, Timestamp('1981-01-07 00:00:00'): 36.0, Timestamp('1981-01-08 00:00:00'): 36.0, Timestamp('1981-01-09 00:00:00'): 36.0, Timestamp('1981-01-12 00:00:00'): 36.0, Timestamp('1981-01-13 00:00:00'): 36.0, Timestamp('1981-01-14 00:00:00'): 36.0, Timestamp('1981-01-15 00:00:00'): 36.0, Timestamp('1981-01-16 00:00:00'): 36.0, Timestamp('1981-01-19 00:00:00'): 36.0, Timestamp('1981-01-20 00:00:00'): 36.0, Timestamp('1981-01-21 00:00:00'): 36.0, Timestamp('1981-01-22 00:00:00'): 36.0, Timestamp('1981-01-23 00:00:00'): 36.0, Timestamp('1981-01-26 00:00:00'): 36.0}, 'Daily_Drawdown': {Timestamp('1980-12-12 00:00:00'): 0.0, Timestamp('1980-12-15 00:00:00'): -0.05217391304347829, Timestamp('1980-12-16 00:00:00'): -0.12173913043478257, Timestamp('1980-12-17 00:00:00'): -0.10017391304347822, Timestamp('1980-12-18 00:00:00'): -0.07373913043478264, Timestamp('1980-12-19 00:00:00'): -0.017391304347826098, Timestamp('1980-12-22 00:00:00'): 0.0, Timestamp('1980-12-23 00:00:00'): 0.0, Timestamp('1980-12-24 00:00:00'): 0.0, Timestamp('1980-12-26 00:00:00'): 0.0, Timestamp('1980-12-29 00:00:00'): 0.0, Timestamp('1980-12-30 00:00:00'): -0.02444444444444449, Timestamp('1980-12-31 00:00:00'): -0.05194444444444435, Timestamp('1981-01-02 00:00:00'): -0.04166666666666663, Timestamp('1981-01-05 00:00:00'): -0.0625, Timestamp('1981-01-06 00:00:00'): -0.10416666666666663, Timestamp('1981-01-07 00:00:00'): -0.14222222222222225, Timestamp('1981-01-08 00:00:00'): -0.1597222222222222, Timestamp('1981-01-09 00:00:00'): -0.11444444444444446, Timestamp('1981-01-12 00:00:00'): -0.12166666666666659, Timestamp('1981-01-13 00:00:00'): -0.1527777777777778, Timestamp('1981-01-14 00:00:00'): -0.14916666666666667, Timestamp('1981-01-15 00:00:00'): -0.13194444444444442, Timestamp('1981-01-16 00:00:00'): -0.13888888888888884, Timestamp('1981-01-19 00:00:00'): -0.08694444444444449, Timestamp('1981-01-20 00:00:00'): -0.11444444444444446, Timestamp('1981-01-21 00:00:00'): -0.09722222222222221, Timestamp('1981-01-22 00:00:00'): -0.08694444444444449, Timestamp('1981-01-23 00:00:00'): -0.09027777777777779, Timestamp('1981-01-26 00:00:00'): -0.10416666666666663}, 'Max_Daily_Drawdown': {Timestamp('1980-12-12 00:00:00'): 0.0, Timestamp('1980-12-15 00:00:00'): -0.05217391304347829, Timestamp('1980-12-16 00:00:00'): -0.12173913043478257, Timestamp('1980-12-17 00:00:00'): -0.12173913043478257, Timestamp('1980-12-18 00:00:00'): -0.12173913043478257, Timestamp('1980-12-19 00:00:00'): -0.12173913043478257, Timestamp('1980-12-22 00:00:00'): -0.12173913043478257, Timestamp('1980-12-23 00:00:00'): -0.12173913043478257, Timestamp('1980-12-24 00:00:00'): -0.12173913043478257, Timestamp('1980-12-26 00:00:00'): -0.12173913043478257, Timestamp('1980-12-29 00:00:00'): -0.12173913043478257, Timestamp('1980-12-30 00:00:00'): -0.12173913043478257, Timestamp('1980-12-31 00:00:00'): -0.12173913043478257, Timestamp('1981-01-02 00:00:00'): -0.12173913043478257, Timestamp('1981-01-05 00:00:00'): -0.12173913043478257, Timestamp('1981-01-06 00:00:00'): -0.12173913043478257, Timestamp('1981-01-07 00:00:00'): -0.14222222222222225, Timestamp('1981-01-08 00:00:00'): -0.1597222222222222, Timestamp('1981-01-09 00:00:00'): -0.1597222222222222, Timestamp('1981-01-12 00:00:00'): -0.1597222222222222, Timestamp('1981-01-13 00:00:00'): -0.1597222222222222, Timestamp('1981-01-14 00:00:00'): -0.1597222222222222, Timestamp('1981-01-15 00:00:00'): -0.1597222222222222, Timestamp('1981-01-16 00:00:00'): -0.1597222222222222, Timestamp('1981-01-19 00:00:00'): -0.1597222222222222, Timestamp('1981-01-20 00:00:00'): -0.1597222222222222, Timestamp('1981-01-21 00:00:00'): -0.1597222222222222, Timestamp('1981-01-22 00:00:00'): -0.1597222222222222, Timestamp('1981-01-23 00:00:00'): -0.1597222222222222, Timestamp('1981-01-26 00:00:00'): -0.1597222222222222}}
在daily_drawdown
列中,在某些实例中,值为0.000
。我想在daily_drawdown
中提取0.000之间的最小值,最好是新列。
例如,前两个0.000之间的最小值为:-0.121739
。稍后在同一列中,将有另一个0.000
,我希望它在第二和第三0.000之间选择该最小值,等等。
Definitely easier to show via an example:
{'Close': {Timestamp('1980-12-12 00:00:00'): 28.75, Timestamp('1980-12-15 00:00:00'): 27.25, Timestamp('1980-12-16 00:00:00'): 25.25, Timestamp('1980-12-17 00:00:00'): 25.87, Timestamp('1980-12-18 00:00:00'): 26.63, Timestamp('1980-12-19 00:00:00'): 28.25, Timestamp('1980-12-22 00:00:00'): 29.63, Timestamp('1980-12-23 00:00:00'): 30.88, Timestamp('1980-12-24 00:00:00'): 32.5, Timestamp('1980-12-26 00:00:00'): 35.5, Timestamp('1980-12-29 00:00:00'): 36.0, Timestamp('1980-12-30 00:00:00'): 35.12, Timestamp('1980-12-31 00:00:00'): 34.13, Timestamp('1981-01-02 00:00:00'): 34.5, Timestamp('1981-01-05 00:00:00'): 33.75, Timestamp('1981-01-06 00:00:00'): 32.25, Timestamp('1981-01-07 00:00:00'): 30.88, Timestamp('1981-01-08 00:00:00'): 30.25, Timestamp('1981-01-09 00:00:00'): 31.88, Timestamp('1981-01-12 00:00:00'): 31.62, Timestamp('1981-01-13 00:00:00'): 30.5, Timestamp('1981-01-14 00:00:00'): 30.63, Timestamp('1981-01-15 00:00:00'): 31.25, Timestamp('1981-01-16 00:00:00'): 31.0, Timestamp('1981-01-19 00:00:00'): 32.87, Timestamp('1981-01-20 00:00:00'): 31.88, Timestamp('1981-01-21 00:00:00'): 32.5, Timestamp('1981-01-22 00:00:00'): 32.87, Timestamp('1981-01-23 00:00:00'): 32.75, Timestamp('1981-01-26 00:00:00'): 32.25}, 'Roll_Max': {Timestamp('1980-12-12 00:00:00'): 28.75, Timestamp('1980-12-15 00:00:00'): 28.75, Timestamp('1980-12-16 00:00:00'): 28.75, Timestamp('1980-12-17 00:00:00'): 28.75, Timestamp('1980-12-18 00:00:00'): 28.75, Timestamp('1980-12-19 00:00:00'): 28.75, Timestamp('1980-12-22 00:00:00'): 29.63, Timestamp('1980-12-23 00:00:00'): 30.88, Timestamp('1980-12-24 00:00:00'): 32.5, Timestamp('1980-12-26 00:00:00'): 35.5, Timestamp('1980-12-29 00:00:00'): 36.0, Timestamp('1980-12-30 00:00:00'): 36.0, Timestamp('1980-12-31 00:00:00'): 36.0, Timestamp('1981-01-02 00:00:00'): 36.0, Timestamp('1981-01-05 00:00:00'): 36.0, Timestamp('1981-01-06 00:00:00'): 36.0, Timestamp('1981-01-07 00:00:00'): 36.0, Timestamp('1981-01-08 00:00:00'): 36.0, Timestamp('1981-01-09 00:00:00'): 36.0, Timestamp('1981-01-12 00:00:00'): 36.0, Timestamp('1981-01-13 00:00:00'): 36.0, Timestamp('1981-01-14 00:00:00'): 36.0, Timestamp('1981-01-15 00:00:00'): 36.0, Timestamp('1981-01-16 00:00:00'): 36.0, Timestamp('1981-01-19 00:00:00'): 36.0, Timestamp('1981-01-20 00:00:00'): 36.0, Timestamp('1981-01-21 00:00:00'): 36.0, Timestamp('1981-01-22 00:00:00'): 36.0, Timestamp('1981-01-23 00:00:00'): 36.0, Timestamp('1981-01-26 00:00:00'): 36.0}, 'Daily_Drawdown': {Timestamp('1980-12-12 00:00:00'): 0.0, Timestamp('1980-12-15 00:00:00'): -0.05217391304347829, Timestamp('1980-12-16 00:00:00'): -0.12173913043478257, Timestamp('1980-12-17 00:00:00'): -0.10017391304347822, Timestamp('1980-12-18 00:00:00'): -0.07373913043478264, Timestamp('1980-12-19 00:00:00'): -0.017391304347826098, Timestamp('1980-12-22 00:00:00'): 0.0, Timestamp('1980-12-23 00:00:00'): 0.0, Timestamp('1980-12-24 00:00:00'): 0.0, Timestamp('1980-12-26 00:00:00'): 0.0, Timestamp('1980-12-29 00:00:00'): 0.0, Timestamp('1980-12-30 00:00:00'): -0.02444444444444449, Timestamp('1980-12-31 00:00:00'): -0.05194444444444435, Timestamp('1981-01-02 00:00:00'): -0.04166666666666663, Timestamp('1981-01-05 00:00:00'): -0.0625, Timestamp('1981-01-06 00:00:00'): -0.10416666666666663, Timestamp('1981-01-07 00:00:00'): -0.14222222222222225, Timestamp('1981-01-08 00:00:00'): -0.1597222222222222, Timestamp('1981-01-09 00:00:00'): -0.11444444444444446, Timestamp('1981-01-12 00:00:00'): -0.12166666666666659, Timestamp('1981-01-13 00:00:00'): -0.1527777777777778, Timestamp('1981-01-14 00:00:00'): -0.14916666666666667, Timestamp('1981-01-15 00:00:00'): -0.13194444444444442, Timestamp('1981-01-16 00:00:00'): -0.13888888888888884, Timestamp('1981-01-19 00:00:00'): -0.08694444444444449, Timestamp('1981-01-20 00:00:00'): -0.11444444444444446, Timestamp('1981-01-21 00:00:00'): -0.09722222222222221, Timestamp('1981-01-22 00:00:00'): -0.08694444444444449, Timestamp('1981-01-23 00:00:00'): -0.09027777777777779, Timestamp('1981-01-26 00:00:00'): -0.10416666666666663}, 'Max_Daily_Drawdown': {Timestamp('1980-12-12 00:00:00'): 0.0, Timestamp('1980-12-15 00:00:00'): -0.05217391304347829, Timestamp('1980-12-16 00:00:00'): -0.12173913043478257, Timestamp('1980-12-17 00:00:00'): -0.12173913043478257, Timestamp('1980-12-18 00:00:00'): -0.12173913043478257, Timestamp('1980-12-19 00:00:00'): -0.12173913043478257, Timestamp('1980-12-22 00:00:00'): -0.12173913043478257, Timestamp('1980-12-23 00:00:00'): -0.12173913043478257, Timestamp('1980-12-24 00:00:00'): -0.12173913043478257, Timestamp('1980-12-26 00:00:00'): -0.12173913043478257, Timestamp('1980-12-29 00:00:00'): -0.12173913043478257, Timestamp('1980-12-30 00:00:00'): -0.12173913043478257, Timestamp('1980-12-31 00:00:00'): -0.12173913043478257, Timestamp('1981-01-02 00:00:00'): -0.12173913043478257, Timestamp('1981-01-05 00:00:00'): -0.12173913043478257, Timestamp('1981-01-06 00:00:00'): -0.12173913043478257, Timestamp('1981-01-07 00:00:00'): -0.14222222222222225, Timestamp('1981-01-08 00:00:00'): -0.1597222222222222, Timestamp('1981-01-09 00:00:00'): -0.1597222222222222, Timestamp('1981-01-12 00:00:00'): -0.1597222222222222, Timestamp('1981-01-13 00:00:00'): -0.1597222222222222, Timestamp('1981-01-14 00:00:00'): -0.1597222222222222, Timestamp('1981-01-15 00:00:00'): -0.1597222222222222, Timestamp('1981-01-16 00:00:00'): -0.1597222222222222, Timestamp('1981-01-19 00:00:00'): -0.1597222222222222, Timestamp('1981-01-20 00:00:00'): -0.1597222222222222, Timestamp('1981-01-21 00:00:00'): -0.1597222222222222, Timestamp('1981-01-22 00:00:00'): -0.1597222222222222, Timestamp('1981-01-23 00:00:00'): -0.1597222222222222, Timestamp('1981-01-26 00:00:00'): -0.1597222222222222}}
In the Daily_Drawdown
column, there are instances in which the value is 0.000
. I want to extract the minimum value of between the 0.000s in Daily_Drawdown
, preferably to a new column.
For example, the minimum value between the first two 0.000s is: -0.121739
. Later on the same column, there will be another 0.000
, and I would like it to pick out that minimum value between the 2nd and 3rd 0.000s, and etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
cumsum
创建一个石斑鱼,以识别由0
隔开的行,然后使用groupby
和transform> transform
with <代码>最小Create a grouper using
cumsum
to identify the groups of rows separated by0
, then usegroupby
andtransform
withmin