I have a data frame called df, and would like to add a column "Return" based on the existing columns by using lambda function. For each row, if value of "Field_3" < 50, then "Return" value would be the value of "Field_1", otherwise it would be "Field_2" value. My code raised a value error: Wrong number of items passed 7, placement implies 1. I'm a Python beginner, any help would be appreciated.
values_list = [[15, 2.5, 100], [20, 4.5, 50], [25, 5.2, 80],
[45, 5.8, 48], [40, 6.3, 70], [41, 6.4, 90],
[51, 2.3, 111]]
df = pd.DataFrame(values_list, columns=['Field_1', 'Field_2', 'Field_3'])
df["Return"] = df["Field_3"].apply(lambda x: df['Field_1'] if x < 50 else df['Field_2'])