I have two columns one has 22 Names and another column with respective credit against each name. I need to know all the combination of 11 names which sums up to 100.
i am attaching image of data for example.
I searched and returned with itertool
which gets you all the combination. But I was not sure of how this can be used to get all the combination.
import pandas as pd
import itertools
from itertools import combinations
from itertools import permutations
data=pd.read_excel(r'C:\Users\anup.kumar.dutta\Documents\Test\Test.xlsx',index=False)
def f(length,total_sum):
if length == 1:
yield (total_sum,)
else:
for value in range(total_sum + 1):
for permutation in sum(length - 1,total_sum - value):
yield (value,) + permutation
L = list(f(5,100))
print('total permutations:',len(L))
It should return all combination of names which sums up to credit 100.