# How to specify \`CSV.read\` column types?

**URL:** <https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984>\
**Category:** General Usage\
**Tags:** question, type, csv\
**Created:** [August 7, 2018, 11:53am UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984 "2018-08-07T11:53:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickhg12hs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickhg12hs/32/5926_2.png) [@rickhg12hs](https://discourse.julialang.org/u/rickhg12hs)\
**Post date:** [August 7, 2018, 11:53am UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984/1 "2018-08-07T11:53:09Z")

</div>

How should column types be specified for `CSV.read`?

This is just some toy data, but I can’t seem to specify the types for it.

```julia
using CSV
iob = IOBuffer("9000,4,473,6473,[1, 1, 0, 1]
9001,4,326,6240,[0, 0, 1, 1]
9002,4,196,6273,[1, 0, 0, 0]")
df = CSV.read(iob, datarow=1)

	Column1	Column2	Column3	Column4	Column5	Column6	Column7	Column8
1 9000 4 473 6473 [1 1 0 1]
2 9001 4 326 6240 [0 0 1 1]
3 9002 4 196 6273 [1 0 0 0]

iob.ptr = 1
df2 = CSV.read(iob, datarow=1, types=fill(Any,8)')

ArgumentError: 8 number of columns detected; `types` argument has 8 entries

Stacktrace:
 [1] #Source#24(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::CSV.Options{Void}, ::Int64, ::Int64, ::RowVector{Any,ConjArray{DataType,1,Array{DataType,1}}}, ::Symbol, ::Void, ::Bool, ::Void, ::Symbol, ::Int64, ::Int64, ::Int64, ::Bool, ::Type{T} where T) at /home/rick/.julia/v0.6/CSV/src/Source.jl:188
 [2] (::Core.#kw#Type)(::Array{Any,1}, ::Type{CSV.Source}) at ./<missing>:0
 [3] #Source#23(::UInt8, ::UInt8, ::UInt8, ::String, ::Void, ::Int64, ::Int64, ::RowVector{Any,ConjArray{DataType,1,Array{DataType,1}}}, ::Symbol, ::Void, ::Void, ::UInt8, ::String, ::String, ::Bool, ::Void, ::Symbol, ::Int64, ::Int64, ::Int64, ::Bool, ::Type{T} where T, ::Base.AbstractIOBuffer{Array{UInt8,1}}) at /home/rick/.julia/v0.6/CSV/src/Source.jl:31
 [4] (::Core.#kw#Type)(::Array{Any,1}, ::Type{CSV.Source}, ::Base.AbstractIOBuffer{Array{UInt8,1}}) at ./<missing>:0
 [5] #read#43(::Bool, ::Dict{Int64,Function}, ::Bool, ::Array{Any,1}, ::Function, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Type{T} where T) at /home/rick/.julia/v0.6/CSV/src/Source.jl:347
 [6] (::CSV.#kw##read)(::Array{Any,1}, ::CSV.#read, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Type{T} where T) at ./<missing>:0 (repeats 2 times)
 [7] include_string(::String, ::String) at ./loading.jl:522

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 7, 2018, 1:07pm UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984/2 "2018-08-07T13:07:57Z")

</div>

The problem is in the `Any` which is an abstract type. Julia can’t parse something into `Any`. If you switch that to, say, `Int`, it’ll work. Also, remove the transpose `'`, it’s not needed.

---

<div class="post-metadata">

**Author:** ![rickhg12hs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rickhg12hs/32/5926_2.png) [@rickhg12hs](https://discourse.julialang.org/u/rickhg12hs)\
**Post date:** [August 7, 2018, 1:20pm UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984/3 "2018-08-07T13:20:29Z")

</div>

Thanks!

Is there an easy way to interpret the last 4 columns in each row of the example data as a single `Vector{Int64}`?

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [August 7, 2018, 1:28pm UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984/4 "2018-08-07T13:28:27Z")

</div>

Nothing like that for now.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 7, 2018, 1:47pm UTC](https://discourse.julialang.org/t/how-to-specify-csv-read-column-types/12984/5 "2018-08-07T13:47:49Z")

</div>

In the long run I think `CSV` needs to be a lot more hackable.
