I have a dataframe that one of the column contains string values, and I want to assign new column if this column values are in the list I specified.
my_list = ['AA', 'TR', 'NZ']
For example: My dataframe : df
| country |
|---|
| AA |
| TR |
| SG |
The dataframe I want to have:
| country | flag |
|---|---|
| AA | 1 |
| TR | 1 |
| SG | 0 |
I tried this one but I gave an Value Error.
df.assign(flag = lambda df: '1' if df['country'].isin(my_list) else '0')
What should I do? Thank you