How to easily rename column of GroupedDataFrame

I think you just need to enclose your anonymous function in brackets if you want to call :a => (x -> somefun(x)) => :new_name)

Compare:

julia> using DataFrames

julia> df = DataFrame(a = rand(1:5, 10), b = rand(10))


julia> combine(groupby(df, :a), :b => (x -> sum(x.^2)) => :c)
4×2 DataFrame
│ Row │ a     │ c         │
│     │ Int64 │ Float64   │
├─────┼───────┼───────────┤
│ 1   │ 4     │ 1.60384   │
│ 2   │ 3     │ 0.0293582 │
│ 3   │ 2     │ 0.787128  │
│ 4   │ 1     │ 1.24591   │

julia> combine(groupby(df, :a), :b => x -> sum(x.^2) => :c)
4×2 DataFrame
│ Row │ a     │ b_function    │
│     │ Int64 │ Pair…         │
├─────┼───────┼───────────────┤
│ 1   │ 4     │ 1.60384=>:c   │
│ 2   │ 3     │ 0.0293582=>:c │
│ 3   │ 2     │ 0.787128=>:c  │
│ 4   │ 1     │ 1.24591=>:c   │
2 Likes