# Combining a dataframe with a Vector{Float64}, and naming the new column something other than "x1"

**URL:** https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093
**Category:** New to Julia
**Created:** [April 6, 2022, 1:19pm UTC](https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093 "2022-04-06T13:19:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)
#### Post date: [April 6, 2022, 1:19pm UTC](https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093/1 "2022-04-06T13:19:58Z")

</div>

I have the following code:

```
`DataFrame([df new_column])`

```

where df is an existing dataframe and new\_column is a Vector{Float64}.

The result creates a new df where the content of new\_column has the name “x1”. How can I set the name of new\_column to something specific as I create the new dataframe?

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [April 6, 2022, 1:27pm UTC](https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093/2 "2022-04-06T13:27:21Z")

</div>

```julia
df.apples=randn(10)

```

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [April 6, 2022, 1:30pm UTC](https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093/3 "2022-04-06T13:30:27Z")

</div>

I believe the typical method is `df.my_specifc_name = new_column` or if you want more control over where in the dataframe the column ends up, try `insertcols!`  
[Functions · DataFrames.jl](https://dataframes.juliadata.org/stable/lib/functions/#DataFrames.insertcols)!

---

<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: [April 6, 2022, 1:55pm UTC](https://discourse.julialang.org/t/combining-a-dataframe-with-a-vector-float64-and-naming-the-new-column-something-other-than-x1/79093/4 "2022-04-06T13:55:21Z")

</div>

Agree with the above but more verbose (and maybe explicit?) is:

```julia
julia> using DataFrames

julia> df = DataFrame(rand(3, 3), :auto)
3×3 DataFrame
 Row │ x1 x2 x3
     │ Float64 Float64 Float64
─────┼──────────────────────────────
   1 │ 0.947632 0.327634 0.252124
   2 │ 0.631133 0.575395 0.657919
   3 │ 0.13491 0.782569 0.222796

julia> insertcols!(df, "new_col" => rand(3))
3×4 DataFrame
 Row │ x1 x2 x3 new_col
     │ Float64 Float64 Float64 Float64
─────┼────────────────────────────────────────
   1 │ 0.947632 0.327634 0.252124 0.74787
   2 │ 0.631133 0.575395 0.657919 0.7908
   3 │ 0.13491 0.782569 0.222796 0.691634

```
