# Populate a Dataframe from an array

**URL:** <https://discourse.julialang.org/t/populate-a-dataframe-from-an-array/35526>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 4, 2020, 3:21pm UTC](https://discourse.julialang.org/t/populate-a-dataframe-from-an-array/35526 "2020-03-04T15:21:24Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 4, 2020, 3:29pm UTC](https://discourse.julialang.org/t/populate-a-dataframe-from-an-array/35526/4 "2020-03-04T15:29:13Z")

</div>

It’s hard to be certain given that your post is not an MWE (see here: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)), but there are a few potential issues.

First of all, you seem to be trying to use dot-notation indexing (`electricity.col_name`) within a loop and using a `String` object (`Node.elements[i].name` seems to be a string based on your struct definition). This won’t work, you need to index the dataframe with a Symbol using `electricity[:, Symbol(col_name)]`. However it seems that the column doesn’t even exist in your DataFrame so you’ll have to create it first.

Also note that `Node.elements` as an array is iterable by itself, no need to use indices:

```julia
for el in Node.elements
    col_name = Symbol(el.name)
    electricity[!, col_name] = max_production(el.resource, el.installed_capacity)
end

```

or something like that at least…

---

_[View the full topic](https://discourse.julialang.org/t/populate-a-dataframe-from-an-array/35526)._
