I have this dataframe:
type run corrected_episode Reward
0 notsweet 0 0 35.0
1 notsweet 0 100 20.0
2 notsweet 0 200 20.0
3 notsweet 0 300 22.0
4 notsweet 0 400 20.0
I want to create a new column, best_so_far, that has a monotonically increasing value for the corresponding Reward grouped by type, run, and corrected_episode. Easy enough, right? Except the following happens when I try to use groupby and cummax:
foo['best_so_far'] = foo.groupby(['type','run','corrected_episode']).Reward.cummax() yields:
type run corrected_episode Reward best_so_far
0 notsweet 0 0 35.0 35.0
1 notsweet 0 100 20.0 20.0
2 notsweet 0 200 20.0 20.0
3 notsweet 0 300 22.0 22.0
4 notsweet 0 400 20.0 20.0
The "best so far", well, isn't the best. I get the same results if I use foo['best_so_far'] = foo.groupby(['type','run','corrected_episode']).Reward.apply(lambda x: x.cummax())
I know this is possible because I've done this dozens of times with other dataframes, there's just something weird about this one that this simple procedure just doesn't work.