3

I am trying to assign a value to a column based on a selection of multiple criteria. I'm trying to create the following logic:

if field1 is null and field2 is null then assign fieldTemp to 0.

I have no problem applying the logic based on one column:

df.loc[df['field1'].isnull(), 'fieldTemp'] = 0

It gets difficult once I try and test for 'field2' is null with and and operator. Anybody know if there is a way to accomplish this?

Michael Rut
  • 1,027
  • 1
  • 11
  • 19

1 Answers1

2

We need two conditions

df.loc[df['field1'].isnull() & df['field3'].isnull(), 'fieldTemp'] = 0
BENY
  • 317,841
  • 20
  • 164
  • 234