DataFrame to Dict via Vector of Nested Named Tuples

I would just do:

julia> Demand.(Loc.(df.City, df.State), df.Part)
3-element Vector{Demand}:
 Demand(Loc("Boston", "MA"), :X)
 Demand(Loc("Dallas", "TX"), :Y)
 Demand(Loc("Chicago", "IL"), :Z)

and since you are coming from R an alternative is:

julia> using DataFramesMeta

julia> @with(df, Demand.(Loc.(:City, :State), :Part))
3-element Vector{Demand}:
 Demand(Loc("Boston", "MA"), :X)
 Demand(Loc("Dallas", "TX"), :Y)
 Demand(Loc("Chicago", "IL"), :Z)
1 Like