I have a df of gambling transactions (small sample below). I want to be able to group the transactions of each unique user, but also to determine each user's success.
import pandas as pd
d = {'user_id': [1234, 5830, 3943, 1234, 5032, 5830,1234 ], 'win': [1, 0, 1, 0, 0, 1, 1],}
df= pd.DataFrame(data=d)
df
I can group the user id's and count to see how many times each occurs, but not do the second part- determine success for each user, would like to see win/loss in real terms and as a ratio for each user.
group = df.groupby('user_id')['user_id'].count()
print(group)
So my output would a a df with these columns 'User', 'Total_wins', 'Total_losses','win_loss_ratio'