Python pandas - new column's value if the item is in the list Python pandas - new column's value if the item is in the list pandas pandas

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     EU0  Washington      USA  Other1      Berlin  Germany     EU2      Moscow   Russia  Other3      Warsaw   Poland     EU