by staticautomatic · 6y ago · 0 comments
The question was "How do I create a column where each row's value is the mean of another column's values starting at that row?" The answer was:
df.loc[::-1, 'col_1'].expanding().mean()[::-1]Separately, I find it upsetting there are at least 6 ways of reversing a dataframe. It suggests some API smell.
df[col].expanding(reverse=True).mean()