Translation groupby and agg and join python to julia

Welcome to our community :confetti_ball:

I would recommend reading this PSA for how to ask questions in this forum. It would be nice if you put triple backticks on your code and posted one or two CSVs instead of an image.

Nate;Text;Month
name1;hej;11
name1;du;11
name1;aj;12
name1;oj;12
name2;finn;11
name2;katt;11
name2;mycket;12
name2;lite;12

I believe that what you want is:

julia> using DataFrames
julia> using CSV
julia> df = DataFrame(CSV.File("data.csv"; delim = ';'))
8×3 DataFrame
 Row │ Nate    Text    Month 
     │ String  String  Int64 
─────┼───────────────────────
   1 │ name1   hej        11
   2 │ name1   du         11
   3 │ name1   aj         12
   4 │ name1   oj         12
   5 │ name2   finn       11
   6 │ name2   katt       11
   7 │ name2   mycket     12
   8 │ name2   lite       12

julia> gdf = groupby(df, [:Nate, :Month]) 
GroupedDataFrame with 4 groups based on keys: Nate, Month
First Group (2 rows): Nate = "name1", Month = 11
 Row │ Nate    Text    Month 
     │ String  String  Int64 
─────┼───────────────────────
   1 │ name1   hej        11
   2 │ name1   du         11
⋮
Last Group (2 rows): Nate = "name2", Month = 12
 Row │ Nate    Text    Month 
     │ String  String  Int64 
─────┼───────────────────────
   1 │ name2   mycket     12
   2 │ name2   lite       12

julia> cdf = combine(gdf, :Text => (xs -> join(xs, '!')))
4×3 DataFrame
 Row │ Nate    Month  Text_function 
     │ String  Int64  String        
─────┼──────────────────────────────
   1 │ name1      11  hej!du
   2 │ name1      12  aj!oj
   3 │ name2      11  finn!katt
   4 │ name2      12  mycket!lite

You can already give the name of the new column if you add a => :NewColName after the anonymous function.

1 Like