I have a df with some binary columns (1,-1) and a list with N columnnames. i need to create a new variable like that ...
df['test'] = np.where(((df['Col1']==-1) & (df['Col2']==-1)), -1, 0)
... but dynamically. so the rule is: if all the columns from the list have the same value (1,-1) take it. otherwise value = 0. the length of the list is not fixed. can i simply iterate over the list and create that "where-String" or is there a more elegant way?
thanks! e