Create Running Total Columns in a Data Frame for Multiple Variables with Dynamic Column Name Creation

What language are you coming from? This looks stata-esque.

The solution here is to do combine. Read the DataFrames docs here for more info.

cumul_vars = ["elo1_pre", "elo2_pre", "qbelo1_pre", "qbelo2_pre", "qb1_value_pre", "qb2_value_pre", "qb1_adj", "qb2_adj", "score1", "score2"]

combine(groupby(df, [:team, :season]), cumul_vars .=> cumsum)

Actually, I think you want to keep existing columns, right? Then you would do

transform(groupby(df, [:team, :season]), cumul_vars .=> cumsum)
2 Likes