# Loading CSV file to TimeSeries data

**URL:** <https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662>\
**Category:** Data\
**Tags:** time-series, csv\
**Created:** [December 6, 2021, 4:42pm UTC](https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662 "2021-12-06T16:42:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [December 6, 2021, 4:42pm UTC](https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662/1 "2021-12-06T16:42:45Z")

</div>

Hi, I am trying to load some OHLC data into TimeArray (from TimeSeries.jl).

The documentation ([Tables.jl Interface Integration · TimeSeries.jl](https://juliastats.org/TimeSeries.jl/stable/tables/#Load-a-TimeArray-from-csv-file-via-CSV.jl-1)) says I can load it directly as

```julia
using CSV
TimeArray(CSV.File(filename), timestamp = :timestamp)

```

But when I try the following code, I get error.

```julia
using TimeSeries
using CSV
filename = "./ohlc-data.csv"
data = TimeArray(CSV.File(filename), timestamp = :time)

```

ERROR:

```julia
MethodError: no method matching TimeArray(::Vector{Int64}, ::Matrix{Float64}, ::Vector{Symbol}, ::CSV.File; unchecked=false)
Closest candidates are:
  TimeArray(::AbstractVector{D}, ::AbstractArray{T, N}, ::Vector{Symbol}, ::Any; args...) where {T, N, D<:TimeType} at ~/.julia/packages/TimeSeries/e3V5T/src/timearray.jl:91
  TimeArray(::D, ::AbstractArray{T, N}, ::Vector{Symbol}, ::Any; args...) where {T, N, D<:TimeType} at ~/.julia/packages/TimeSeries/e3V5T/src/timearray.jl:96
  TimeArray(::AbstractVector{D}, ::AbstractArray{T, N}, ::Vector{S}, ::Any; args...) where {T, N, D<:TimeType, S<:AbstractString} at deprecated.jl:70
  ...

Stacktrace:
 [1] TimeArray(x::CSV.File; timestamp::Symbol, timeparser::Function, unchecked::Bool)
   @ TimeSeries.TablesIntegration ~/.julia/packages/TimeSeries/e3V5T/src/tables.jl:82
 [2] top-level scope
   @ In[6]:4
 [3] eval
   @ ./boot.jl:360 [inlined]
 [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

```

My ohlc data file is of format

```julia
time,low,high,open,close,volume
<unixtimestamp>,<float>,<float>,<float>,<float>,<float>
...

```

How can I fix this error?

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [December 6, 2021, 5:32pm UTC](https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662/2 "2021-12-06T17:32:18Z")

</div>

> [@v-i-s-h](#):
>
> `TimeArray(CSV.File(filename), timestamp = :time)`

I experienced the same error when trying to do this. A quick fix would be to just load to a DataFrame first…

---

<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:** [December 7, 2021, 4:23am UTC](https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662/3 "2021-12-07T04:23:14Z")

</div>

From what I can tell, the `TimeArray` constructor requires the timestamp column to be some kind of `TimeType`, so like `Date`s or `DateTime`s, but in your case, you have a `Vector{Int}` (from the backtrace). And from your file, it looks like your time column is `<unixtimestamp>`, so you’ll want to convert. It looks like the constructor takes a “converter” function, so I _think_ this should work for you:

```julia
data = TimeArray(CSV.File(filename), timestamp = :time, timeparser = Dates.unix2datetime)

```

Otherwise, I’d open an issue at the [https://github.com/JuliaStats/TimeSeries.jl/blob/master/src/tables.jl](https://github.com/JuliaStats/TimeSeries.jl/blob/master/src/tables.jl) package and get some direct help there.

---

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [December 7, 2021, 4:39am UTC](https://discourse.julialang.org/t/loading-csv-file-to-timeseries-data/72662/4 "2021-12-07T04:39:46Z")

</div>

Thanks a lot. Adding timeparser worked! I was having unixtimestamp as the first column and adding the parser helped it to load. 😀
