# How to add new column to Dataframe

**URL:** <https://discourse.julialang.org/t/how-to-add-new-column-to-dataframe/58794>\
**Category:** Data\
**Tags:** question, dataframes\
**Created:** [April 7, 2021, 10:27pm UTC](https://discourse.julialang.org/t/how-to-add-new-column-to-dataframe/58794 "2021-04-07T22:27:41Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [April 8, 2021, 12:12am UTC](https://discourse.julialang.org/t/how-to-add-new-column-to-dataframe/58794/5 "2021-04-08T00:12:46Z")

</div>

You can insert a new column into the _first_ position with `insertcols`.

```julia
insertcols!(B, 1, :a => A.IID)

```

You can also use a `leftjoin` (or other `join` types) if the orders don’t match exactly.

For the `collapse`-ing operation

```julia
@chain df begin 
    groupby("Herd.when.genotyped")
    combine(:x1 => mean)
end

```

To get the mean of all the columns, do

```julia
@chain df begin 
    groupby("Herd.when.genotyped")
    combine(names(df, Between(:x1, :x5)) .=> mean)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-add-new-column-to-dataframe/58794)._
