Hello everyone,
I modified my code, it should be faster than the last one above, but still pretty long when I need to find 5 of 60...
Instead of comparing every combination like before, I putting in a dict index/score, then I sort by score and looking at the first indexes where sum-average) - sum(MVP) is under 121:
Do you have any tips/hints to go faster ?
I read numpy is faster than dataframe, but didn't really work yet with it
I modified my code, it should be faster than the last one above, but still pretty long when I need to find 5 of 60...
Instead of comparing every combination like before, I putting in a dict index/score, then I sort by score and looking at the first indexes where sum-average) - sum(MVP) is under 121:
df1 = pd.DataFrame.from_dict(data) for index in list(combinations(df1.index,5)): dictIndexScore[index] = df1.loc[index,:]["Score1"].sum(axis=0) for i in sorted(dictIndexScore.items(), key=lambda x:x[1], reverse=True): if df1.loc[i[0],:]["10Aver1"].sum(axis=0) - df1.loc[i[0],:]["10Aver1"].max(axis=0) < 121: bestIndex = i[0] bestSum = i[1] break print(df1.loc[bestIndex,:])My program did 3366.6575298309326 seconds for a 60 rows dataframe, so 5461512 combinations possible of 5 in 60...
Do you have any tips/hints to go faster ?
I read numpy is faster than dataframe, but didn't really work yet with it