# DataFrame | multiply set of colums

**URL:** <https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [January 15, 2020, 9:48pm UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421 "2020-01-15T21:48:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 15, 2020, 9:48pm UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421/1 "2020-01-15T21:48:13Z")

</div>

Would you suggest,  
I have a list of columns (many of them). How to multiply all of them.

I know how to sum, but I have no idea, how to multiply

> sum.(eachrow(qf[:,[:a,:b]]))

Thanks

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [January 15, 2020, 11:19pm UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421/2 "2020-01-15T23:19:25Z")

</div>

```julia
prod.(eachcol(df))
prod.(eachrow(df))

```

or

```julia
prod(Matrix(df), dims=1)
prod(Matrix(df), dims=2)

```

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 15, 2020, 11:20pm UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421/3 "2020-01-15T23:20:11Z")

</div>

These work:

```julia
prod(Matrix(df), dims=1)

```

or if you want DataFrame

```julia
prod(Matrix(df), dims=1) |> x->DataFrame(x, names(df))

```

or

```julia
reduce((x, y)->Vector(x) .* Vector(y), eachrow(df)) |> x->DataFrame(x', names(df))

```

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 15, 2020, 11:26pm UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421/4 "2020-01-15T23:26:56Z")

</div>

`prod.(eachcol(df))` is very clever. Why can’t I think of that…

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 16, 2020, 12:09am UTC](https://discourse.julialang.org/t/dataframe-multiply-set-of-colums/33421/5 "2020-01-16T00:09:33Z")

</div>

thanks. yes, it’s very clear. for some reasons, I tried mul. =))
