标题不是最好的,但我不知道如何在一行中描述我的问题。
我遇到的问题是,我想计算一些值,比如A, B, C, D,是否按顺序出现。
<表类>
B
C
D
总
tbody><<tr>1 1 0 0 0 0 0 1 0 0 1 ! 0 0 1 0 0 1 ! 0 0 0 0 0 1 ! 0 0 0 0 0 1 ! 1 表类>
尝试shift
和np.prod
:
# we shift `A` by 3 rows, `B` by 2, ...
# then take product of the shifted values
df['Total'] = np.prod([df[col].shift(3-i, fill_value=0)
for i,col in enumerate(['A','B','C','D'])],
axis=0)