Mean of each column in a DataFrame?

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

mean.(eachcol(df))

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

3 Likes

Thanks!

How about a comprehension?

Using DataFrames, Statistics

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

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

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