Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: aggregation function for wrapdims (and populate!) #107

Open
fredcallaway opened this issue Mar 22, 2022 · 0 comments
Open

Comments

@fredcallaway
Copy link

This is basically what pandas.pivot_table does. Here's a naive implementation. I imagine this could be done more efficiently though.

julia> function wrap_reduce(df, aggregator, val, keys...)
    grp = groupby(df, collect(keys))
    agg = combine(grp, val => aggregator => :_val)
    wrapdims(agg, :_val, keys...)
end

julia> df = DataFrame([
    1 1
    1 1
    1 2
    2 3
    2 5
], ["x", "y"])

julia> wrap_reduce(df, sum, :y, :x)
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
   x  2-element Vector{Int64}
And data, 2-element Vector{Int64}:
 (1)  4
 (2)  8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant