pouchewar
pouchewar

Reputation: 399

How to groupby 200 features at once using Julia

I am looking for a way to perform these operations in julia:

From a daframe I have 200 columns that I want to groupby one-by-one doing this:

column1_grouped = combine(df,column_1),[:fixed_parameter] .=> mean)
column2_grouped = combine(df,column_2),[:fixed_parameter] .=> mean)

untill column200_grouped.

Is there a way to iterate over a list of these 200 columns to output these 200 grouped dataframes? (I want to avoid type 200 lines like the above)

I got the list of 200 columns doing: list = names(df[!,r"factor_"])

Upvotes: 1

Views: 28

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69819

Here is an example where the result will be a Dict mapping grouping column name to resulting data frame:

list = names(df, r"factor_")
Dict([n => combine(groupby(df, n), :fixed_parameter => mean) for n in list])

Upvotes: 1

Related Questions