samedi 31 août 2019

How do I nest an if statement within a function

I would like to nest a conditional if statement within a function, but I am not sure what the correct syntax is. Right now I have:

def answer_one()

  x=dataframe
  perRenew = x['% Renewable'].mean()
  x['Highrenew'] = 0

    if x['% Renewable'] >= perRenew :
       x['Highrenew'] = 1
    else:
       x['Highrenew'] = 0

  return x

But when I run the code I get ValueError: The truth value of a Series is ambiguous

What are some correct ways/ best practices to get the job done?

Aucun commentaire:

Enregistrer un commentaire