0
Hello! I’ve been trying to check if a certain value present in a certain dataframe column is present in a list, using np.Where.
In other words, it would look like this:
df = {
'Pais': ['Brazil', 'Colombia', 'Argentina', 'EUA'],
'PIB' : [1000, 1056, 1070, 410]
}
df = pd.DataFrame(df)
america_do_sul = ['Brazil', 'Colombia', 'Argentina', 'Peru', 'Venezuela', 'Ecuador', 'Bolivia', 'Paraguay', 'Uruguay']
df['Sulamericano'] = np.where(df['Pais'] in america_do_sul, 1, 0)
The idea of code is to create a column in my dataframe called 'South American' where it has the value '1' for yes and '0' for not.
However, when this code is executed it generates the following error:
Valueerror: The Truth value of a Series is ambiguous. Use a.Empty, a. bool(), a.item(), a.any() or a.all().
Note: The figures in the GDP column are fictitious!
– Jose Edmario