I've tried searching this on Stack Overflow but don't seem to be able to find the same scenario. I'm trying to update multiple columns in my pandas dataframe in one line of code with same function. I can update each column individually, but want the function to update multiple columns simultaneously.
The function is basic:
binary_values = lambda x: 0 if x == -99 else 1
I know I can assign scalar values to sections of the dataframe like this:
df.ix[:,22:26] = 1
I'm trying to do something like below:
df.ix[:,22:26] = df.ix[:,22:26].apply(binary_values)
...but it throws up ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index..')