I am building a recommender system of foods and I have a dataframe:
df:
meat vegetables cheese ketchup egg...
hamburger 3 5 2 2 1
pasta 0 0 4 0 1
soup 0 2 0 0 0
...
I also have a list which contains ingredients that an user does not like:
dislike:["cheese", "egg"]
So what I am trying to do is to create a function which adds a new row "user_name" with a 10 in those ingredients that he/she does not like and a 0 in all the others columns. Output should be:
meat vegetables cheese ketchup egg...
hamburger 3 5 2 2 1
pasta 0 0 4 0 1
soup 0 2 0 0 0
new_user 0 0 10 0 10
...
I have simplify the dataframe and the list in order to make it more comprehensive, but they are actually way more longer.
This is what I have write until now:
def user_pre(df):
dislike=["cheese","egg"]
for ing in dislike:
df.loc["new_user"]= pd.Series({ing:10})
return df
I "works" but only for the last element in dislike list. Besides it does not add a 0 in the other cells but a Nan.
Thank you so much in advance!