0

I'm using a dataframe within a function to alter that dataframe. I get thrown this error:

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

def hello(column):
    if data['State'] == 'CA': 
        answer = column * 3 
    return answer  

This is the outter thing I'm trying to do:

data['sup'] = data['Amount paid'].apply(hello, axis=1) 

'State' is a series of states like CA, VA, NY etc. 'Amount paid' is a number.

I'm trying to make it so that if the State is CA, multiply that row's 'Amount paid' by 3.

1 Answers1

1

data['State'] is a Series. Therefore, data['State'] == 'CA' is also a Series of boolean values. Do you want all of them to be true for the condition to be true? Or just some of them? In the former case, use if (data['State'] == 'CA').all():. In the latter case, if (data['State'] == 'CA').any():

DYZ
  • 55,249
  • 10
  • 64
  • 93