dimanche 31 mai 2020

dataframe: ValueError: The truth value of a Series is ambiguous

I am not sure why I am getting this strange error for this simple if condition. I have added the function funt to check values in each row of column 'Owner', first I am checking if row in column 'Owner has any of these values [ 'hal','jula','huli'], if yes then it should return 'cont'. This returned value will be used to create new column(team) in dataframe df. Whenever I try to run below code I get this error.

def funt(row):
  if df['Owner'] in ['hal','jula','huli']:   # error line
     return 'cont'
  elif df['Owner'] == "assigned":
     return "unassigned"
  elif df['Owner'] == "Other":
     return "Other"
  else:
     return "Something else"

df['team'] = df.apply(lambda row: funt(row), axis=1)

Error:

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

Aucun commentaire:

Enregistrer un commentaire