def foo(x):
temp = x[x.iloc[-1]-2 == x]
if len(temp):
return x.index[-1] - temp.index[-1]
else:
return 0
df['B'] = df['A'].expanding(1).apply(foo)
【 在 Tnnnnn 的大作中提到: 】
: 我想添加一个新列['B'],数值根据['A']列相应位置的数值而定
: A B
: 0 4
: ...................
--
FROM 115.193.87.*