# Convert dictionary of dataframes into single dataframe

**URL:** <https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255>\
**Category:** General Usage\
**Created:** [March 30, 2021, 6:21pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255 "2021-03-30T18:21:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![waforbes](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@waforbes](https://discourse.julialang.org/u/waforbes)\
**Post date:** [March 30, 2021, 6:21pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/1 "2021-03-30T18:21:11Z")

</div>

I have a dictionary of dataframes that I want to combine into a single dataframe.

![image](https://global.discourse-cdn.com/julialang/original/3X/e/2/e2943b616b23df8299b2b65524be4dc2c42bd26c.png)

---

<div class="post-metadata">

**Author:** ![waforbes](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@waforbes](https://discourse.julialang.org/u/waforbes)\
**Post date:** [March 30, 2021, 6:21pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/2 "2021-03-30T18:21:40Z")

</div>

This didn’t work.

test2 = hcat(speed\_steps)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/3/635df83adfd320d2baf9a02cb5e72a2ebb0b1d51.png)

---

<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:** [March 30, 2021, 6:33pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/3 "2021-03-30T18:33:48Z")

</div>

I think you probably want `vcat` rather than `hcat`.

```julia
reduce(vcat, values(speed_steps))

```

---

<div class="post-metadata">

**Author:** ![waforbes](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@waforbes](https://discourse.julialang.org/u/waforbes)\
**Post date:** [March 30, 2021, 7:26pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/4 "2021-03-30T19:26:46Z")

</div>

[pdeffebach](https://discourse.julialang.org/u/pdeffebach),

Yes, that worked. Thanks!

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [March 30, 2021, 7:27pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/5 "2021-03-30T19:27:08Z")

</div>

If you, or another reader stumbling across this topic, also want to add the keys to the DataFrame, you can iterate over the keys and values and add the keys as a column to the individual data frames. For example,

```julia
julia> A = DataFrame(TimeInterval = [1])
1×1 DataFrame
 Row │ TimeInterval
     │ Int64
─────┼──────────────
   1 │ 1

julia> B = DataFrame(TimeInterval = [2])
1×1 DataFrame
 Row │ TimeInterval
     │ Int64
─────┼──────────────
   1 │ 2

julia> speeds = Dict(0.3 => A, 0.9 => B)
Dict{Float64, DataFrame} with 2 entries:
  0.3 => 1×1 DataFrame…
  0.9 => 1×1 DataFrame…

julia> for (speed, df) in zip(keys(speeds), values(speeds))
       df[!, :speed] .= speed
       end;

julia> vcat(values(speeds)...)
2×2 DataFrame
 Row │ TimeInterval speed
     │ Int64 Float64
─────┼───────────────────────
   1 │ 1 0.3
   2 │ 2 0.9
```

---

<div class="post-metadata">

**Author:** ![waforbes](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@waforbes](https://discourse.julialang.org/u/waforbes)\
**Post date:** [March 30, 2021, 8:46pm UTC](https://discourse.julialang.org/t/convert-dictionary-of-dataframes-into-single-dataframe/58255/6 "2021-03-30T20:46:57Z")

</div>

[rikh](https://discourse.julialang.org/u/rikh),

Thanks. I probably will eventually need to do that. I’m making the jump from Python. There’s been a slight learning curve for me.
