for example, I have the next list:
l = ['a', 'x', 't']
and the DataFrame:
a = [{'sufix': 'a', 'qty': 5}, {'sufix': 'b', 'qty': 2}, {'sufix': 'c', 'qty': 7}, {'sufix': 'x', 'qty': 9}, {'sufix': 't', 'qty': 4}, {'sufix': 'p', 'qty': 1}]
df = pd.DataFrame(a)
print(df)
What I need, if values from list -> l are in column df['sufix'] -> create new column df['yes'] and put value from column df['qty'], else df['yes'] = 0
I need the next result:
>Solution :
If I understand you correctly, probably something like this:
df['yes'] = df['qty'][df['sufix'].isin(l)]
df['yes'] = df['yes'].fillna(0)
