Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if value of dataframe is existing in list

I am trying to split a pandas Dataframe into two, based on the value in the column "country".

If the value exists in the following list (EU-COUNTRY-CODES), the row should be added to a dataframe called "EU", if it does not exist in the list I want to add the row to another dataframe.

eu-country-codes = ["BE","BG","DK","EE","FI","FR","GR","IE","IT","HR","LV","LT","LU","MT","NL","AT","PL","PT","RO","SM","SE","SK","SI","ES","CZ","HU","VA","FO","CY"]

I tried to do it this way but got following Error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

data = pd.read_csv("datei.csv", sep=",", header=0)
eu= data[data["country"] not in eu-country-codes]

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

>Solution :

try this:

data[data["country"].isin( eu-country-codes)==False]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading