I have the following 2 tables, df and name_df, where the number of people is not limited to 2 and can increase. Under the name columns (ie. John and Mary), a 1 represents he/she consumed the item while 0 represents did not consume:
df
item price John Mary
apple 2 1 1
mango 5 0 1
name_df
name
John
Mary
I want to calculate the sumproduct of each person and join the column to the name_df column. I want the result to look like this:
name_df
name sumproduct
John 2
Mary 7
My main problem is to find out how to calculate sumproduct using python/pandas. I know a .dot()
function will get the result I want but how can I append those results to each respective person?