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
  • 37,862
  • 7
  • 57
  • 71
Mastodon87
  • 325
  • 3
  • 6
  • 14

0 Answers0