# Help with exporting data to .CSV

**URL:** <https://discourse.julialang.org/t/help-with-exporting-data-to-csv/54410>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [February 1, 2021, 7:25pm UTC](https://discourse.julialang.org/t/help-with-exporting-data-to-csv/54410 "2021-02-01T19:25:07Z")\
**Posts on this page:** 2\
**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 1, 2021, 7:25pm UTC](https://discourse.julialang.org/t/help-with-exporting-data-to-csv/54410/1 "2021-02-01T19:25:07Z")

</div>

Hello everybody!

I am trying to export only the numeric data of the result of the variable `r` to a `.CSV`. The model does not give an error, but I cannot export the data as I need it.

I would like the data to be written in `.CSV` this way

```julia

│ Row │ value │
│ │ Int64 │
├─────┼───────┤
│ 1 │ 0 │
│ 2 │ 0 │
│ 3 │ 0 │
│ 4 │ 0 │ 

```

However it is written this way for `.CSV`

```julia
│ Row │ value │
│ │ String │
├─────┼─────────────────┤
│ 1 │ r:2 dimensions: │

```

Why can’t I export the data the way I want?

As the model is, it may not make much sense because it is a cut out of a model that I am building.  
Thank you!

```julia
using JuMP, GLPK, CSV, DataFrames, GLPKMathProgInterface
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("r = ", JuMP.getvalue(r))

valueresult = DataFrame(value=JuMP.getvalue(r))
CSV.write("C:\\Users\\raquel.santos\\Desktop\\testemodel.csv",valueresult)#CSV file path, file that has only one field called "value"

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 1, 2021, 7:36pm UTC](https://discourse.julialang.org/t/help-with-exporting-data-to-csv/54410/2 "2021-02-01T19:36:44Z")

</div>

`r` is a 4x4 matrix, so it doesn’t make sense to try and store it as a single column in a data frame.

If you skip CSV, you can do something like:

```nohighlight
open("test_model.csv", "w") do io
    for a in A
        println(io, join([getvalue(r[a, t]) for t in T], ", "))
    end
end

```

Again, I would encourage you to upgrade to the latest version of JuMP.
