# How to export data from an array

**URL:** <https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555>\
**Category:** Data\
**Tags:** question, jump\
**Created:** [February 3, 2021, 7:38pm UTC](https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555 "2021-02-03T19:38:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [February 3, 2021, 7:38pm UTC](https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555/1 "2021-02-03T19:38:05Z")

</div>

Maybe my question is a little repetitive compared to the last one I posted here.  
In this model, I would like to export the data that is in `i` to a `.CSV` file.  
When compiling the model the answer I have in `.CSV` is this:

```julia
[150.0 150.0 151.0 151.0]

```

The answer I want to get is:

```julia
│ Row │ │ │
│ │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1 │ 150.0 │ 151.0 │
│ 2 │ 150.0 │ 151.0 │

```

Why can’t I export the array data in the same way that I can view the data in `i`?

Thanks!!!

```julia
using JuMP,CSV,DataFrames,DelimitedFiles

i = [150.0 151.0; 150.0 151.0]

#.CSV with all fields empty
open("C:\\Users\\raquel.santos\\Desktop\\testemodel.csv", "w") do io
    writedlm(io, [i])
end
readdlm("C:\\Users\\raquel.santos\\Desktop\\testemodel.csv",Float64)

```

---

<div class="post-metadata">

**Author:** ![pyrex41](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@pyrex41](https://discourse.julialang.org/u/pyrex41)\
**Post date:** [February 3, 2021, 7:45pm UTC](https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555/2 "2021-02-03T19:45:39Z")

</div>

```julia
arr = [150.0 150.0 151.0 151.0]

df = reshape(arr, 2,2) |> DataFrame

CSV.write("myfilename", df)

```

For more information on dataframes, check out the docs [Getting Started · DataFrames.jl](https://dataframes.juliadata.org/stable/man/getting_started/#Importing-and-Exporting-Data-(I/O))

---

<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:** [February 3, 2021, 8:54pm UTC](https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555/3 "2021-02-03T20:54:46Z")

</div>

Note that in the snippet above `i` is already defined as a 2x2 matrix, so `CSV.write("testemodel.csv", DataFrame(i))` would be sufficient.

---

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [February 4, 2021, 6:29pm UTC](https://discourse.julialang.org/t/how-to-export-data-from-an-array/54555/4 "2021-02-04T18:29:49Z")

</div>

Thank you for your help @nilshg and @pyrex41 !!  
Despite being able to export the data, I still haven’t been able to view it the way I need it.  
Here’s the model I’m working on

```julia
using JuMP,CSV, DataFrames, GLPK, GLPKMathProgInterface, DelimitedFiles
Modeltest = Model(solver = GLPKSolverMIP())

a = 1:4
t = 1:4
w = 1:2

A = a
T = t
W = w

#Parameters
CR = [11, 12]
CO =[50, 51]
WA = [1, 2, 1, 2]
RHE = [150, 151]

#Variables
@variable(Modeltest,r[A,T]>=0)
@variable(Modeltest,o[A,T]>=0)
@variable(Modeltest,wr[W,T]>=0)
@variable(Modeltest,er[W,T]>=0)

@objective(Modeltest,Min,sum(CR[WA[a]]*(r[a,t]+o[a,t])+CO[WA[a]]*o[a,t] for a in A, t in T))

for w = 1:2, t= 1:4
    m = @constraint(Modeltest,sum(r[a,t] for a in A) +wr[w,t] ==RHE[w])
    #println(m)
end

print(Modeltest)
status = solve(Modeltest)
println("Objective value: ", JuMP.getobjectivevalue(Modeltest))

println("wr = ", JuMP.getvalue(wr))

open("testemodel.csv", "w") do io
    println(io, join([getvalue(wr[W, T])]))
    #writedlm(io, join([getvalue(wr[W, T])]))
end

p = readline("testemodel.csv")
#p = readdlm("testemodel.csv")
println(p)

```

Perhaps I have expressed it wrongly, my question is: How to manipulate the data in an array?  
espite having already used `writedlm` and `readdlm`, I can’t export the data to `.CSV` the way I need it.  
When exporting the data to `.CSV` this is the answer I have:

```julia
|150.0 150.0 150.0 150.0 | 151.0 151.0 151.0 151.0|

```

This is the answer I would like to get, each data in a field as in a table

```julia

│ Row │ value │ value2 │
│ │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1 │ 150.0 │ 151.0 │
│ 2 │ 150.0 │ 151.0 │
│ 3 │ 150.0 │ 151.0 │
│ 4 │ 150.0 │ 151.0 │

```
