I\'m giving a toy example but it will help me understand what\'s going on for something else I\'m trying to do. Let\'s say I want a new column in a dataframe \'optimal_fruit
If you do not want to repeat df2 for each column:
[row[0][0]*row[0][1]-row[0][2] for row in zip(df2[['apples', 'oranges', 'bananas']].to_numpy())]
or
def func(row):
print(row[0]*row[1]-row[2])
[func(*row) for row in zip(df2[['apples', 'oranges', 'bananas']].to_numpy())]
See also:
EDIT:
Please use df.iloc and df.loc instead of df[[...]], see Selecting multiple columns in a pandas dataframe