0

I have a datafram df, and i want to get the rows that a column value equals 1 b 0 c 0 and d 0

df_result = df[df.a == 1 and df.b == 0 and df.c == 0 and df.d == 0]

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

SeaBean
  • 22,547
  • 3
  • 13
  • 25
Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37

1 Answers1

3

Use & instead of and and put brackets around each value test:

df_result = df[(df.a == 1) & (df.b == 0) & (df.c == 0) & (df.d == 0)]

Alternatively, to avoid using extra brackets, you can use .eq():

df_result = df[df.a.eq(1) & df.b.eq(0) & df.c.eq(0) & df.d.eq(0)]
SeaBean
  • 22,547
  • 3
  • 13
  • 25