Brandon Edwards
Brandon Edwards

Reputation: 107

Pushing array contents to DataFrame - Julia

I have an array X that I would like to push onto a DataFrame at regular intervals. Suppose the array is of size 7. Currently, I am doing:

push!(df, (week, X[1], X[2], X[3], X[4], X[5], X[6], X[7], sum(X)))

Is there an easier way to output this array, like a loop of some sort? I'm sure it's a simple answer but I haven't been able to find anything in the documentation.

Upvotes: 2

Views: 1054

Answers (1)

niczky12
niczky12

Reputation: 5063

Posting my comment as answer.

It seems like what you want to achieve here is to create new vector as a combination of vectors and single values. You can achieve this by using the vcat() function which combines your objects vertically into as single array.

Instead of:

(week, X[1], X[2], X[3], X[4], X[5], X[6], X[7], sum(X))

You can create the same object as such:

vcat(week, X, sum(X))

And then push!() this to your original dataframe as before.

Upvotes: 2

Related Questions