# How to split up a Float column in array or dataframe (not String)

**URL:** <https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406>\
**Category:** New to Julia\
**Created:** [May 29, 2020, 9:42am UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406 "2020-05-29T09:42:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [May 29, 2020, 9:42am UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/1 "2020-05-29T09:42:58Z")

</div>

Hello, there are a few topics about splitting up columns in a Dataframe or Table that are strings e.g.  
[https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718](https://discourse.julialang.org/t/juliadb-split-one-column-into-n-columns/20718)  
[https://stackoverflow.com/questions/57184663/how-to-convert-comma-separated-values-in-a-dataframe-cell-into-an-array-in-julia](https://stackoverflow.com/questions/57184663/how-to-convert-comma-separated-values-in-a-dataframe-cell-into-an-array-in-julia)

But I cannot find how to do this with `Floats`.

I have an array/DataFrame (first I create the array and later I turn it into a dataframe) and I want to split up the second column into five parts.

```julia
 Row │ Time │ x2 │
│ │ Any │ Any │
├───────┼─────────┼─────────────────────────────────────────────────────┤
│ 1 │ 0.0 │ (0.00912906, 0.70303, 0.182395, -3.25295, 1.90496) │
│ 2 │ 1.0 │ (0.00915032, 0.70303, 0.182026, -3.25192, 1.9049) │
│ 3 │ 2.0 │ (0.00917156, 0.70303, 0.181659, -3.2509, 1.90485) │
│ 4 │ 3.0 │ (0.00919279, 0.70303, 0.181295, -3.24988, 1.90479) │

```

MWE

```julia
Time= 0.0
x2 = (0.00912906, 0.70303, 0.182395, -3.25295, 1.90496)
data_frame_test = [Time x2]

```

With `String` this is done by `DataFrame(split.(data_frame_test, ","))` but this doesn’t apply here. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [May 29, 2020, 10:51am UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/2 "2020-05-29T10:51:54Z")

</div>

```julia
Time= 0.0
x2 = (0.00912906, 0.70303, 0.182395, -3.25295, 1.90496)
data_frame_test = [Time x2...]
dt = DataFrame(data_frame_test)

```

Note the … in data\_frame\_test. This i called splatting.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [May 29, 2020, 11:07am UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/3 "2020-05-29T11:07:36Z")

</div>

Thank you for your reply. Your suggestion is correct for my MWE.

I receive an error and see my MWE was not correct. Unfortunately I do not know how to make a different MWE. In this case, `x2` is a `Vector{NTuple{5,Float64}}`.

I receive the error

```julia
DimensionMismatch("mismatch in dimension 1 (expected 50001 got 1)")
in top-level scope at Schneider et al 2016 running.jl:220
in hcat at base\abstractarray.jl:1544
in at base\abstractarray.jl:1564
in #cat#110 at base\abstractarray.jl:1564
in _cat at base\abstractarray.jl:1435
in at base\abstractarray.jl:1437
in #cat_t#109 at base\abstractarray.jl:1437
in _cat_t at base\abstractarray.jl:1440
in cat_shape at base\abstractarray.jl:1395
in cat_shape at base\abstractarray.jl:1395
in _cshp at base\abstractarray.jl:1416 
in _cs at base\abstractarray.jl:1420

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 29, 2020, 12:50pm UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/4 "2020-05-29T12:50:19Z")

</div>

Is it something like the following?

```julia
julia> x2 = [(1,2,3)]
1-element Array{Tuple{Int64,Int64,Int64},1}:
 (1, 2, 3)

julia> x2[1]
 (1, 2, 3)

```

If so, try to change line

```julia
data_frame_test = [Time x2...]

```

to

```julia
data_frame_test = [Time x2[1]...]

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [May 29, 2020, 2:19pm UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/5 "2020-05-29T14:19:18Z")

</div>

You want a broadcasted `getindex`

```julia
julia> 
julia> df = DataFrame(a = [(rand(), rand()) for i in 1:10]);

julia> for i in 1:2
       df[:, "a$i"] = getindex.(df.a, i)
       end;

julia> df
10×3 DataFrame
│ Row │ a │ a1 │ a2 │
│ │ Tuple{Float64,Float64} │ Float64 │ Float64 │
├─────┼────────────────────────┼───────────┼───────────┤
│ 1 │ (0.856342, 0.307311) │ 0.856342 │ 0.307311 │
│ 2 │ (0.0181747, 0.899767) │ 0.0181747 │ 0.899767 │
│ 3 │ (0.637947, 0.155305) │ 0.637947 │ 0.155305 │
│ 4 │ (0.641775, 0.33356) │ 0.641775 │ 0.33356 │
│ 5 │ (0.292641, 0.33817) │ 0.292641 │ 0.33817 │
│ 6 │ (0.0669127, 0.0544888) │ 0.0669127 │ 0.0544888 │
│ 7 │ (0.880316, 0.655488) │ 0.880316 │ 0.655488 │
│ 8 │ (0.812024, 0.0369003) │ 0.812024 │ 0.0369003 │
│ 9 │ (0.742961, 0.78381) │ 0.742961 │ 0.78381 │
│ 10 │ (0.377581, 0.257949) │ 0.377581 │ 0.257949 │

```

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 2, 2020, 8:55am UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/6 "2020-06-02T08:55:34Z")

</div>

When I use your example code, I get

```julia
ERROR: MethodError: no method matching setindex!(::DataFrame, ::Array{Float64,1}, ::String)

```

@BLI It still wasn’t working so I resaved it as a `Vector{Float64}` and it works now.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 2, 2020, 1:49pm UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/7 "2020-06-02T13:49:06Z")

</div>

What version of DataFrames are you using?

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 2, 2020, 2:41pm UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/8 "2020-06-02T14:41:18Z")

</div>

```julia
  [a93c6f00] DataFrames v0.20.2

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 2, 2020, 2:43pm UTC](https://discourse.julialang.org/t/how-to-split-up-a-float-column-in-array-or-dataframe-not-string/40406/9 "2020-06-02T14:43:51Z")

</div>

If you update DataFrames, you will be able to do `df[:, "a string"]` rather than using symbols everywhere. But my code snipped above works if you replace `df[:, "a$i"]` with `df[:, Symbol(:a, i)]`.
