更新时间:2023-11-30 13:24:46
您可以使用numpy select()
You can use the numpy select()
import pandas as pd
import numpy as np
condition = [(df.column1==1) & (df.column2==1) & (df.column3==1) & (df.column4==1)]
choices = [1]
df['output'] =np.select(condition, choices, default= 0)
如果您有多列,则可以使用np.apply_along_axis()
if you have multiple columns you can use the np.apply_along_axis()
def ex(x):
a = 0
if x.all() == 1.0:
a = 1
return a
df['output'] = np.apply_along_axis(ex,1,df)