transaction startdate
1 0 1 0
答案 0 :(得分:1)
检查get_indexer
和values
切片
s=df.filter(like='/')
idcol=s.columns.get_indexer(df.TransDate)
df['PreviousDayDummy']=(s.values[np.arange(len(s)),idcol-1]==df.lookup(df.index,df.TransDate)).astype(int)
df
Out[72]:
Transaction TransDate Cashier PreviousDayDummy 01/01 01/02 01/03
0 1 01/02 2 1 1 1 1
1 2 01/02 1 0 0 1 1
2 3 01/02 2 1 1 1 1
3 4 01/03 3 0 0 0 1