Skip to content

Convert DataFrames.DataFrame <-> TimeSeries.TimeArray #46

Closed
@femtotrader

Description

@femtotrader

Hello,

I'm looking for a way to convert DataFrames.DataFrame to (and from) TimeSeries.TimeArray using IterableTables.jl.
but it doesn't seems to work as I was expecting

TimeSeries.TimeArray -> DataFrames.DataFrame

Create TimeSeries.TimeArray

julia> using TimeSeries
julia> dat = "Date,Open,High,Low,Close,Volume
2012-01-03,11.0,11.25,10.99,11.13,45709900
2012-01-04,11.15,11.53,11.07,11.3,79725200
2012-01-05,11.33,11.63,11.24,11.59,67877500
2012-01-06,11.74,11.8,11.52,11.71,59840700
2012-01-09,11.83,11.95,11.7,11.8,53981500
2012-01-10,12.0,12.05,11.63,11.8,121750600
2012-01-11,11.74,12.18,11.65,12.07,63806000"
julia> io2 = IOBuffer(dat)
julia> ta2 = readtimearray(io2)

Convert to DataFrame

julia> using IterableTables
julia> using DataFrames
julia> DataFrame(ta2)
7×6 DataFrames.DataFrame
│ Row │ timestamp  │ Open  │ High  │ Low   │ Close │ Volume    │
├─────┼────────────┼───────┼───────┼───────┼───────┼───────────┤
│ 12012-01-0311.011.2510.9911.134.57099e7 │
│ 22012-01-0411.1511.5311.0711.37.97252e7 │
│ 32012-01-0511.3311.6311.2411.596.78775e7 │
│ 42012-01-0611.7411.811.5211.715.98407e7 │
│ 52012-01-0911.8311.9511.711.85.39815e7 │
│ 62012-01-1012.012.0511.6311.81.21751e8 │
│ 72012-01-1111.7412.1811.6512.076.3806e7

works fine but...

DataFrames.DataFrame -> TimeSeries.TimeArray

Create DataFrames.DataFrame

julia> using DataFrames
julia> dat = "Date,Open,High,Low,Close,Volume
2012-01-03,11.0,11.25,10.99,11.13,45709900
2012-01-04,11.15,11.53,11.07,11.3,79725200
2012-01-05,11.33,11.63,11.24,11.59,67877500
2012-01-06,11.74,11.8,11.52,11.71,59840700
2012-01-09,11.83,11.95,11.7,11.8,53981500
2012-01-10,12.0,12.05,11.63,11.8,121750600
2012-01-11,11.74,12.18,11.65,12.07,63806000"
julia> io = IOBuffer(dat)
julia> df = readtable(io)
julia> df[:Date] = Date(df[:Date])

Convert to TimeSeries.TimeArray

julia> using IterableTables
julia> using TimeSeries
julia> TimeArray(df[[:Date, :Open, :High, :Low, :Close]], timestamp_column=:Date)
ERROR: MethodError: no method matching TimeSeries.TimeArray(::DataFrames.DataFrame; timestamp_column=:Date)

Any idea?

Kind regards

PS:
Following JuliaStats/TimeSeries.jl#290
and femtotrader/TimeSeriesIO.jl#19

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions