我有一个数据帧-
df = pd.DataFrame({'A':[1,1,0,0,0,0,1,1,0],'B':[0,0,0,0,1,1,0,0,0]})
现在我要计算A列中1,1与B列中0110模式的最近出现次数。
我有0110(colB)中第一个1的索引,这里是4,我得到的答案是-2,因为列a(索引6,7)中的对11后面有2个索引。你知道吗
我对010模式的尝试-
anchor = index_value
hnops = min((anchor - df[df.A != 0].index), key=abs)
Tags:
我认为这是更好的与numpy列表理解完成:
然后你可以从Apos中找到Bpos中每一个元素的最小值
相关问题 更多 >
编程相关推荐