# \[Query.jl\] Way to map many variables to a single function

**URL:** <https://discourse.julialang.org/t/query-jl-way-to-map-many-variables-to-a-single-function/56675>\
**Category:** Data\
**Tags:** query\
**Created:** [March 7, 2021, 1:29pm UTC](https://discourse.julialang.org/t/query-jl-way-to-map-many-variables-to-a-single-function/56675 "2021-03-07T13:29:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Storopoli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/storopoli/32/209278_2.png) [@Storopoli](https://discourse.julialang.org/u/Storopoli)\
**Post date:** [March 7, 2021, 1:29pm UTC](https://discourse.julialang.org/t/query-jl-way-to-map-many-variables-to-a-single-function/56675/1 "2021-03-07T13:29:50Z")

</div>

Here is the code in `DataFrames`:

```nohighlight
@chain DataFrame(tbl) begin
    dropmissing([:NT_GER, :NT_FG, :NT_CE])
    groupby([:TP_SEXO, :CO_TURNO_GRADUACAO], skipmissing=true)
    combine(nrow,
            [:NT_GER, :NT_FG, :NT_CE] .=> mean)
end

```

how do I do it in `Query.jl` but using a single instruction to `@map` to mean. I have to keep repeating myself like this:

```julia
Tables.datavaluerows(tbl) |>
    @dropna(:NT_GER, :NT_FG, :NT_CE, :TP_SEXO, :CO_TURNO_GRADUACAO) |>
    @groupby({_.TP_SEXO, _.CO_TURNO_GRADUACAO}) |>
    @map({
        sexo = key(_)[1],
        turno = key(_)[2],
        nrows = length(_),
        NT_GER_mean = mean(_.NT_GER),
        NT_FG_mean = mean(_.NT_FG),
        NT_CE_mean = mean(_.NT_CE)
    }) |> 
    DataFrame

```

Is there something like?:

```nohighlight
@map({
        sexo = key(_)[1],
        turno = key(_)[2],
        nrows = length(_),
       {_.NT_GER, _.NT_FG, _.NT_CE} = mean(_)
})

```
