My dataframe has two columns with mean values of Team_A and Team_B scoring a goal in a match. For each row, I want to create a 3 by 3 matrix that covers all the possible score line using a Poisson distribution. Here is the first few rows of my data,
d = {'Team_A':[2.0160, 1.3421, 2.4654, 3.0281], 'Team_B':[0.0653, 1.5641, 4.0241, 1.2375]}
df = pd.DataFrame(data=d)
So from the first-row Team A should win the match with the score [2-0] (rounded to nearest integer)
. Assuming scores are independent and occurs in an interval and using the formula for Poisson distribution,
P(k wins in interval) = ((lambda**k) * exp(-lambda))/factorial(k)
where k = [0,1,2,3]
Team A scores 0, 1, 2 and 3 goals with prob. [0.1332, 0.2685, 0.2707, 0.1819] respectively.
And, Team B scores 0, 1, 2 and 3 goals with [0.5205, 0.3399, 0.1110, 0.0242] probabilities.
The table below is constructed by element-wise multiplication of the above probabilities.
For example the implied prob. of a 2-0 Team A win = 0.2707 * 0.5205 = 0.140899
Team_A Goals 0 1 2 3
Team_B Goals Poisson for no.of_goal/Team 0.1332 0.2685 0.2707 0.1819
0 0.5205 0.0693 0.1398 0.1409 0.0947
1 0.3399 0.0453 0.0913 0.0920 0.0618
2 0.1110 0.0148 0.0298 0.0030 0.0202
3 0.0242 0.0032 0.0065 0.0065 0.0044
Question
I'm lost in how to write a python function that loops through each row and create a 3 by 3 matrix.