Skip to content
Advertisement

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:

JavaScript

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?

Advertisement

Answer

Use isin for check membership:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement