import pandas as pd
prizes = ([1, 100], [2, 50], [3, 25])
prizes = pd.DataFrame(prizes, columns=['Rank', 'Payout'])
ranking = ([1, 3, 2], [2, 2, 1], [3, 1, 3])
ranking = pd.DataFrame(ranking, columns=[1, 2, 3])
payouts = pd.DataFrame(range(1, 4), columns=['Lineup'])
mapper = prizes.set_index('Rank')['Payout'].to_dict()
payouts = pd.concat([payouts, ranking[range(1, 4)].apply(lambda s: s.map(mapper)).fillna(-1)], axis=1)
print(ranking)
print(payouts)
1 2 3
0 1 3 2
1 2 2 1
2 3 1 3
Lineup 1 2 3
0 1 100 25 50
1 2 50 50 100
2 3 25 100 25
The lambda function that is just above the print statements, is there any way to write that more efficiently. This is just a small example of what I'm using it for inside a large loop. This one portion of the loop takes roughly about half of the time of the entire loop. Any help would be appreciated.