简体   繁体   中英

Creating a new columns based on values of other columns

I would like to create a columns which checks if there exists a specific value in a column list. This value is Y=1. What I tried already is

mask = df[col_list] ==1 

Which gives me the output for every column individually. But I want a evaluater which checks for every line in the col_list if there exists a Y=1 and if there exists one gives out True. What I would like to have:

df['evaluator'] = df[col_list].eval(col_list[line = i] == 1 for one column then return True)

Is this possible with eval? How should I build the expression?

Thank you!

尝试这个:

df[col_list].eq(1).any(axis=1) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM