# Mean of each column in a DataFrame?

**URL:** <https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105>\
**Category:** New to Julia\
**Created:** [October 10, 2020, 11:38am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105 "2020-10-10T11:38:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 10, 2020, 11:38am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105/1 "2020-10-10T11:38:13Z")

</div>

Hi!

What would be the cleanest way to find the mean of each column in a dataframe? I would like to avoid writing for loops, since I think it should be possible without it.

Kind regards

---

<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:** [October 10, 2020, 11:43am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105/2 "2020-10-10T11:43:36Z")

</div>

`mean.(eachcol(df))`

the mean is also reported when you do `describe(df)` alongside some other summary stats

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 10, 2020, 11:45am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105/3 "2020-10-10T11:45:00Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![Jakob](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jakob](https://discourse.julialang.org/u/Jakob)\
**Post date:** [October 10, 2020, 11:45am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105/4 "2020-10-10T11:45:11Z")

</div>

How about a comprehension?

```julia
Using DataFrames, Statistics

df = DataFrame(a=rand(100), b=rand(100))

[mean(c) for c in eachcol(df)]

```

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 10, 2020, 11:45am UTC](https://discourse.julialang.org/t/mean-of-each-column-in-a-dataframe/48105/5 "2020-10-10T11:45:40Z")

</div>

Also cool, now I can do it in different ways if I want too - thanks
