-1

I am getting this error when I try to add a column to my pandas dataset based on the following conditions.

df['name'] = (1 if (df['name2'] > 0) and (df['name3'] == 0) else 0)

I would really appreciate some help with this, I am very new to python.

Thanks.

anona
  • 11
  • 2

1 Answers1

0

You can use numpy.where:

df['name'] = np.where((df['name2'] > 0) & (df['name3'] == 0), 1, 0)
NYC Coder
  • 7,424
  • 2
  • 11
  • 24