Python pandas – new column’s value if the item is in the list

Use isin for check membership:

df1["EU"] = np.where(df1["Country"].isin(EU), "EU", "Other")
print (df1)
      Capital  Country     EU
0  Washington      USA  Other
1      Berlin  Germany     EU
2      Moscow   Russia  Other
3      Warsaw   Poland     EU

Leave a Comment