# How to combine multiple SummaryStats objects into a single DataFrame?

**URL:** <https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747>\
**Category:** New to Julia\
**Tags:** dataframes, data\_structures\
**Created:** [January 12, 2024, 9:03pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747 "2024-01-12T21:03:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [January 12, 2024, 9:03pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747/1 "2024-01-12T21:03:36Z")

</div>

I am apparently still missing some basic data manipulation skills. Is there a quick way to create a dataframe where the first row contains `sx`, and second row contains `sy` with the appropriate column names?

```julia
julia> using StatsBase, DataFrames

julia> sx = summarystats(rand(10))
Summary Stats:
Length: 10
Missing Count: 0
Mean: 0.534381
Std. Deviation: 0.327727
Minimum: 0.046431
1st Quartile: 0.375997
Median: 0.521883
3rd Quartile: 0.772281
Maximum: 0.980553

julia> sy = summarystats(rand(10))
Summary Stats:
Length: 10
Missing Count: 0
Mean: 0.606235
Std. Deviation: 0.196903
Minimum: 0.377681
1st Quartile: 0.477612
Median: 0.566537
3rd Quartile: 0.719057
Maximum: 0.960698

```

I can write my own function to do this by extracting each element, but it seems like there should be a one-liner.

---

<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:** [January 12, 2024, 9:10pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747/2 "2024-01-12T21:10:40Z")

</div>

No, there is nothing built-in for this. You could do `DataFrame([sy])`?

---

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [January 12, 2024, 9:21pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747/3 "2024-01-12T21:21:54Z")

</div>

Thanks. This is much better than what I was thinking:

```julia
julia> df = DataFrame([sx])
1×9 DataFrame
 Row │ mean sd min q25 median q75 max nobs nmiss 
     │ Float64 Float64 Float64 Float64 Float64 Float64 Float64 Int64 Int64 
─────┼────────────────────────────────────────────────────────────────────────────────────
   1 │ 0.480167 0.267154 0.0865253 0.261997 0.532114 0.66425 0.801299 10 0

julia> df = vcat(df, DataFrame([sy]))
2×9 DataFrame
 Row │ mean sd min q25 median q75 max nobs nmiss 
     │ Float64 Float64 Float64 Float64 Float64 Float64 Float64 Int64 Int64 
─────┼─────────────────────────────────────────────────────────────────────────────────────
   1 │ 0.480167 0.267154 0.0865253 0.261997 0.532114 0.66425 0.801299 10 0
   2 │ 0.382722 0.323311 0.0674511 0.156531 0.19415 0.650376 0.963897 10 0

```

I’ll mark it as answered but still seems like there could be a one-liner like `DataFrame([sx], [sy], ...)`

---

<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:** [January 12, 2024, 9:23pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747/4 "2024-01-12T21:23:51Z")

</div>

Yeah it’s easy

```julia
DataFrame([sx, sx])

```

---

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [January 12, 2024, 9:27pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747/5 "2024-01-12T21:27:22Z")

</div>

Thought I tried that one… Thanks!
