mercredi 28 novembre 2018

if statement python for column values

I am attempting to write the following logic in python:

if column A is '123' and column B is '456', then column c = 0

I've tried the following function, but returns an error:

 def testfunc(df):
     if df['columna'] == 123:
         if df['columnb'] ==456:
             df['columnc']=0

 return df
 testfunc()

error:

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

What am i doing wrong?

Aucun commentaire:

Enregistrer un commentaire