# CSV reading in mutable struct error reading Int as string

**URL:** <https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [July 9, 2021, 6:41am UTC](https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323 "2021-07-09T06:41:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [July 9, 2021, 6:41am UTC](https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323/1 "2021-07-09T06:41:27Z")

</div>

Hi All,  
While putting csv data in a struct getting the error for the below.

```nohighlight
localpath = string("D:\\crane_intensity\\")
mutable struct GeneralDetail
   B::UInt8
   C::UInt8
   P::UInt8
   T::UInt8
   Cs_m::Array{UInt8,1}
   Cs_mv::Array{UInt8,1}
end

GeneralDetails=GeneralDetail[];

df = CSV.read(string(localpath,"input.csv"))

for row in 1:1
         println(df[row,1],",",df[row,2],",", df[row,3],",",df[row,4],",", df[row,5],",", df[row,6])
     push!(GeneralDetails, GeneralDetail( df[row,1], df[row,2], df[row,3], df[row,4], df[row,5], df[row,6]));

end

```

RROR: LoadError: MethodError: Cannot `convert` an object of type String to an object of type UInt8  
Closest candidates are:  
convert(::Type{T\<:Number}, ::T\<:Number) where T\<:Number at number.jl:6  
convert(::Type{T\<:Number}, ::Number) where T\<:Number at number.jl:7  
convert(::Type{T\<:Integer}, ::Ptr) where T\<:Integer at pointer.jl:23  
…  
Stacktrace:  
[1] GeneralDetail(::String, ::String, ::String, ::String, ::String, ::String) at D:\crane\_intensity\test.jl:4  
[2] top-level scope at D:\crane\_intensity\test.jl:18  
in expression starting at D:\crane\_intensity\test.jl:16

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 9, 2021, 8:38am UTC](https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323/2 "2021-07-09T08:38:33Z")

</div>

Hi,

without the input file, we can’t help you to debug this. Seems like CSV.jl detects some column that you think of as a `UInt8` as a string. Can you share (at least some part of) the file?

---

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [July 9, 2021, 8:40am UTC](https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323/3 "2021-07-09T08:40:22Z")

</div>

| Bays | Cranes | PODS | Container\_Type\_Load | Crane\_speed\_moves/min | Crane\_speed\_container/move | | | | | | | | | | |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 18 | 3 | 3 | 5 | 1, 1, 1 | 1, 1, 1 | | | | | | | | | | |
| 4, 6, 8, 10 | | | | | | | | | | | | | | | |
| 3, 7, 5 | | | | | | | | | | | | | | | |
| 2, 1 | | | | | | | | | | | | | | | |

---

<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:** [July 9, 2021, 8:51am UTC](https://discourse.julialang.org/t/csv-reading-in-mutable-struct-error-reading-int-as-string/64323/4 "2021-07-09T08:51:56Z")

</div>

It looks like your file has entries like `4, 6, 8, 10` in some cells, which CSV will treat as a String.

CSV is not a great format for saving nested structures like vectors of vectors, but at the same time I wonder what you would expect to happen here when you get to row 2 in your example and the constructor gets called with `4,6,8,10` as the `B` argument?
