I'd like to get records with country codes not in a long list , something along the lines of

country_list = ['BR','MX','CO',...]
df = df[df['country_code'] not in country_list]

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

what's an elegant way to do it?


1 Answer 1

df = df[~df['country_code'].isin(country_list)]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.