Reputation: 25
I could not find the way to export to CSV files with multiple columns in Julia language.
I need to export the results of my model to a csv or excel file. I wanted to find the way to export multiple variables to multiple columns, so that I don´t have to export each variable to a different csv file.
For example you have:
X = [1, 2, 3]; Y = [0, 0, 0, 0];
How can you get X in one column, and Y in another column of the same csv file?
Thank you very much in advance,
Upvotes: 2
Views: 1573
Reputation: 524
You can also create a DataFrame
with two columns, and export it to CSV using writetable
or CSV.write
(from the CSV.jl package). One of the advantages of this approach over creating an array is that you don't need to copy the column vectors, and that they can be of different types.
Upvotes: 1
Reputation: 4181
I would make an array of empty (or space-filled) strings and then fill with X and Y.
e.g.
X = [1, 2, 3]; Y = [0, 0, 0, 0];
out = fill(" ",maximum(length.([X,Y])),2)
out[1:length(X),1] = string.(X); out[1:length(Y),2] = string.(Y)
writecsv("jnk.csv",out)
Upvotes: 4