I'm trying to add values to a pandas data frame based on the combinations of a user's and an agent's choices. Here's what i tried so far.
import random
import numpy as np
import pandas as pd
from itertools import product
ls = np.zeros((9,3))
choices = ['R','P','S']
df = pd.DataFrame(ls, columns = list(choices), index=[''.join(l) for l in
product(choices, repeat=2)])
user_choices = ['R','S']
agent_choices = ['P','R']
i = 0
while i < 1000:
i +=1
user_choice = random.choice(choices)
agent_choice = random.choice(choices)
user_choices.append(user_choice)
agent_choices.append(agent_choice)
df[user_choices[i-1]][np.char.add(user_choices[i-2] ,agent_choices[i-2])] +=1
This results to getting an indexing error while the indexes exist.
Expected output should be as this example but obviously populated