I have a data frame with columns car_x and car1_y, van2_x and van2_y, and bus3_x and bus3_y. I need a column that is car1_x * car1_y + van2_x * van2_y + bus3_x * bus3_y
The following code doesn't work:
modes = 'car', 'van', 'bus'
for mode in modes:
df['{var}'] = df['{var}_x']*df['{var}_y']
I would then just sum across df['car'], df['van'] and df['bus'] but the syntax above is off.