0

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:

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().
1
  • eu = data[~data["country"].isin(eu-country-codes)] I believe Commented Aug 25, 2022 at 16:37

1 Answer 1

1

try this:

data[data["country"].isin( eu-country-codes)==False]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I love those problems where is waste my lifetime thanks to less than 10 letters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.