Categories
conditional-statements numpy pandas python

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

I want to create a new column in pandas dataframe. The first column contains names of countries. The list contains countries I am interested in (eg. in EU). The new colum should indicate if country from dataframe is in the list or not.

Below is the shortened version of the code:

import pandas as pd
import numpy as np
EU = ["Austria","Belgium","Germany"]
df1 = pd.DataFrame(data={"Country":["USA","Germany","Russia","Poland"], "Capital":["Washington","Berlin","Moscow","Warsaw"]})
df1["EU"] = np.where(df1["Country"] in EU, "EU", "Other")

The error I get is:

ValueError: The truth value of a Series is ambiguous. Use a.empty,
a.bool(), a.item(), a.any() or a.all().

I don’t know what the problem is and how to solve it. What am I missing?