Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Populate a Dataframe from an array

$
0
0

@Luigi_Bottecchia wrote:

Hi all! I’m learning Julia and these are my first steps. I have a struct that looks like this:

struct Region
    elements::Array{res_tech}
    demand::Matrix{Float64}
end

where res_tech is another struct that is:

struct res_tech
    priority::Int
    resource::Matrix{Float64}
    installed_capacity::Int
    name::String
end

Now, I have created a struct based on region that is

Node = Region([wind,pv],el_dem)

where wind and pv are 2 res_tech. I want to create a dataframe (let’s call it electricity) that has as column name the res_tech.name and it’s filled the resulting from a function that multiplies res_tech.resource by res_tech.installed_capacity.

I tried several things and this is the last one:

electricity = DataFrame()

for i in eachindex(Node.elements)
    col_name = Node.elements[i].name
    electricity.col_name = max_production(Node.elements[i].resource,Node.elements[i].installed_capacity)
end

However I get this error:

DimensionMismatch("Array could not be broadcast to match destination")

Can you help me out with this issue?

Thanks a lot!
Luigi

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles