0

I am trying to subset a pandas dataframe based on several conditions. I have attempted something like this:

subset_df = df[((df['language'] != 'es') and (df['language'] == 'eu')) | ((df['language'] == 'es') and (df['lang_conf'] < 1))]

But I get this error:

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

Any ideas of how I could make this work or some different solution to achieve subsetting based on several nested conditions?

pollinei
  • 5
  • 5

1 Answers1

1

You have to replace and by &, like this:

subset_df = df[((df['language'] != 'es') & (df['language'] == 'eu')) | ((df['language'] == 'es') & (df['lang_conf'] < 1))]
Bruno Mello
  • 4,448
  • 1
  • 9
  • 39