I have a dictionary of dataframes that I want to combine into a single dataframe.
I think you probably want vcat
rather than hcat
.
reduce(vcat, values(speed_steps))
3 Likes
Yes, that worked. Thanks!
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> 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
1 Like
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.
1 Like