I have dataframe like this
A Type B C D
Train X 23 230 22
Car Y 0 2 500
Judge Z 222 1 600
Is it possible to create a new DF based on the values in the row?
I have the following function:
def quant(x):
if x>0:
return 1
else:
return 0
Which I then want to apply on some columns of the df
df.apply(lambda row: quant(row[['B','C', 'D']]), axis=1, result_type='expand')
To create new columns with the mapped values based on the function
A Type B_mapped C_mapped D_mapped
Train X 1 1 1
Car Y 0 1 1
Judge Z 1 1 1
However my code returns the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What is the most efficient way to kind of map columns in this way?