julia> transform(groupby(df,names(df, String)), names(df, String) .=> t->replace(t,""=>missing))
10×6 DataFrame
Row │ col1 col2 c3 c4 c3_function c4_function
│ Int64 Int64 String String String? String?
─────┼────────────────────────────────────────────────────────
1 │ 7 8 c3 c4 c3 c4
2 │ 5 5 c3 c3 missing
3 │ 2 8 c4 missing c4
4 │ 6 1 c3 c4 c3 c4
5 │ 9 10 c3 c4 c3 c4
6 │ 10 2 c3 c3 missing
7 │ 2 10 c3 c4 c3 c4
8 │ 8 10 c3 c4 c3 c4
9 │ 6 9 c4 missing c4
10 │ 1 9 missing missing
you could try this subterfuge too, although it costs you extra work to rename the columns.
But I’m just bringing this up to clarify that it doesn’t work if you use renamecols=false
julia> df = DataFrame(col1 = rand(1:10,10), col2 = rand(1:10,10),c3=rand(["","c3"],10),c4=rand(["","c4"],10))
10×4 DataFrame
Row │ col1 col2 c3 c4
│ Int64 Int64 String String
─────┼──────────────────────────────
1 │ 7 8 c3 c4
2 │ 5 5 c3
3 │ 2 8 c4
4 │ 6 1 c3 c4
5 │ 9 10 c3 c4
6 │ 10 2 c3
7 │ 2 10 c3 c4
8 │ 8 10 c3 c4
9 │ 6 9 c4
10 │ 1 9
gstr=groupby(df,names(df, String))
julia> transform(groupby(df,names(df, String)), names(df, String) .=> t->replace(t,""=>missing), renamecols=false)
ERROR: ArgumentError: column :c3 in returned data frame is not equal to grouping key :c3
solved adding ,keepkeys=false
keywarg:
julia> transform(groupby(df,names(df, String)), names(df, String) .=> t->replace(t,""=>missing), renamecols=false,keepkeys=false)
10×4 DataFrame
Row │ col1 col2 c3 c4
│ Int64 Int64 String? String?
─────┼────────────────────────────────
1 │ 7 8 c3 c4
2 │ 5 5 c3 missing
3 │ 2 8 missing c4
4 │ 6 1 c3 c4
5 │ 9 10 c3 c4
6 │ 10 2 c3 missing
7 │ 2 10 c3 c4
8 │ 8 10 c3 c4
9 │ 6 9 missing c4
10 │ 1 9 missing missing