# JuliaDB - split one column into n columns

**URL:** <https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718>\
**Category:** General Usage\
**Tags:** juliadb\
**Created:** [February 12, 2019, 6:35pm UTC](https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718 "2019-02-12T18:35:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pazzo83](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pazzo83/32/232_2.png) [@pazzo83](https://discourse.julialang.org/u/pazzo83)\
**Post date:** [February 12, 2019, 6:35pm UTC](https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718/1 "2019-02-12T18:35:14Z")

</div>

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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 12, 2019, 10:17pm UTC](https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718/2 "2019-02-12T22:17:31Z")

</div>

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
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?)
