So I have a table that looks like this, and I would like to calculate the win rate after each game played. So for player 1, the win rate will start at 100% since he won the first game, then 50% since he lost the second game, then 33%, then back to 50% again.
PlayerId Status
1 1
1 0
1 0
1 1
so the final table will look something like this
PlayerId Status Win_Rate
1 1 100%
1 0 50%
1 0 33%
1 1 50%
You can
.groupbyPlayerId and useexpanding().mean():You can then drop the index level and assign it as a column if you want it on your original frame:
If you want it as a string percentage, you can do extra formatting: