【发布时间】:2021-10-20 14:35:53
【问题描述】:
大家早上好
我试图从 itertools.combination 函数生成的元组列表中插入索引 [0] 和索引 1 到变量 x 和 y 中
在这些链接'itertools.combinations' object is not subscriptable我发现组合中的对象不可下标,并且想知道是否有办法将单独的元组索引获取到函数中
a = [10,11,12,13,14,15]
b = combinations(a,2)
x= b[0]
y= b[1]
conditions = [df[f'sma_{x}'] > df[f'sma_{y}'],
df[f'sma_{x}'] < df[f'sma_{y}']]
choices = [1, -1]
df[f'sma_{x} & sma_{y}'] = np.select(conditions, choices, default=0)
【问题讨论】:
标签: python list tuples combinations itertools