'Calculate probabilities in Pandas for each permutation

I have the following dataframe with 6 numbers and its individual probabilities:

enter image description here

I have created another dataframe with the permutations of those numbers, without the probabilities with the following code:

 from  itertools import product
    #if you need to specify columns
    df7 = pd.DataFrame(list(product(*[df_tot2['Primer'], df_tot2['Segon'], df_tot2['Tercer'], df_tot2['Quart'], df_tot2['Cinque'], df_tot2['Sise']])))
    df7

And it looks like this for some numbers:

enter image description here

Now, I want to add to my new dataframe the total probabilities of each number. I have tried to add the individual probabilities first with a loop depending on each number, but it is not working:

type_new = pd.Series([])

for i in range(len(df7)):
    if df7[0][i] == "4":
        type_new[i]=df_tot2['Prob Primer'][0]
 
    elif df7[0][i] == "3":
        type_new[i]=df_tot2['Prob Primer'][1]
 
    else: 
        type_new[i]=df_tot2['Prob Primer'][2]

If I print type_new is full with the probability of 2 in the first column (0.28). Why is it not working? Is there any other way to calculate this? I feel like I would have to write a lot of code.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source