我有一张表格如下(黑色)。我想在右边创建一个额外的列,例如红色可见。基本上对于"切片中的每个切片变量"列,我想从"低"中检索相应的值。列。
我已经尝试了无数种方法,我已经在这里发布了一个问题,试图解决其中一种方法,但我会工作:
Python Pandas: Function doesn't work when used with apply()
该问题的一位受访者建议我只是问如何实现它,因此我就是这样。
我也在代码下面重新发布以重建该数据帧:
df = pd.DataFrame(dict, columns=["low", "slices"])
{'low': {0: 1207.25,
1: 1207.5,
2: 1205.75,
3: 1206.0,
4: 1201.0,
5: 1202.75,
6: 1203.75},
'slices': {0: [slice(1, 1, None)],
1: [slice(1, 2, None), slice(2, 2, None)],
2: [slice(1, 3, None), slice(2, 3, None), slice(3, 3, None)],
3: [slice(1, 4, None),
slice(2, 4, None),
slice(3, 4, None),
slice(4, 4, None)],
4: [slice(1, 5, None),
slice(2, 5, None),
slice(3, 5, None),
slice(4, 5, None),
slice(5, 5, None)],
5: [slice(1, 6, None),
slice(2, 6, None),
slice(3, 6, None),
slice(4, 6, None),
slice(5, 6, None),
slice(6, 6, None)],
6: [slice(1, 7, None),
slice(2, 7, None),
slice(3, 7, None),
slice(4, 7, None),
slice(5, 7, None),
slice(6, 7, None),
slice(7, 7, None)]}}