I have the following data frame and a list.
d = ({
'Item' : ['a','a','a','b','b','b','b'],
'Count' : [0,1,2,3,4,5,6],
})
df = pd.DataFrame(data = d)
list_factor=[10,100] # a list of factors with same length as the unique Items in dataframe.
Now I would like for each item, multiply the count by list_factor element correspond to that item. For example all counts in a will be multiplied by 10 and all counts in b will be multiplied by 100. So the final data frame will looks like this:
'Item' : ['a','a','a','b','b','b','b'],
'Count' : [0,10,20,300,400,500,600],
I tried to use groupby function and apply a multiplication function to it, but I can do it only for a constant value, not a value from the list. Here is what I did:
df.groupby('Item')['Count'].apply(lambda x : x*list_factor[?!])
This is just an example data frame and what I want to reach. In reality I have a data frame with 1000 different Items and as a result a list_factor with length of 1000. (The data frame has total rows of 40000)