JuliaDB - split one column into n columns

juliadb

#1

Hi, had a question about splitting a single column into multiple new columns. Let’s say I have a table with a column like this:

Table with 8434 rows, 2 columns:
STATION        WND
───────────────────────────────
"72473323170"  "999,9,C,0000,1"
"72473323170"  "010,1,N,0015,1"
"72473323170"  "150,1,N,0021,1"
"72473323170"  "999,9,C,0000,1"
"72473323170"  "120,1,N,0026,1"
"72473323170"  "150,1,N,0041,1"
"72473323170"  "140,1,N,0051,1"
"72473323170"  "140,1,N,0046,1"
"72473323170"  "150,1,N,0041,1"
"72473323170"  "150,1,N,0036,1"

Is there a more efficient way to split that second column up by the comma and generate new columns aside from:
pushcol(tbl, :new_column => getindex.(split.(select(tbl, :WND), ','), 1)), :new_column2 => etc...

Thanks!


#2

Not sure about efficiency in terms of execution time, but maybe a cleaner way is to turn the result of the split operation into a DataFrame and work with that?

julia> s = ["a,b,c", "d,e,f"]
2-element Array{String,1}:
 "a,b,c"
 "d,e,f"

julia> DataFrame(split.(s, ","))
3×2 DataFrame
│ Row │ x1        │ x2        │
│     │ SubStrin… │ SubStrin… │
├─────┼───────────┼───────────┤
│ 1   │ a         │ d         │
│ 2   │ b         │ e         │
│ 3   │ c         │ f         │

(Not sure about rows vs columns here, as you might want to end up with a, d in column1 based on your question?)