0

I have a lot of dummy variables (T/F) that I want to convert to 1/0 with a function, I've tried the one below but it is not working...thanks for your help!

def function_country(row):
    if row == 'True':
        val = 1
    else:
        val = 0
    return val

df2.apply(function_country,axis=1)

ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index 0')
Sheldore
  • 35,129
  • 6
  • 43
  • 58
Mastodon87
  • 323
  • 3
  • 6
  • 13

0 Answers0