TimeDataFrames.jl 722 Bytes
Newer Older
Michel Juillard's avatar
Michel Juillard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module TimeDataFrames

using CSV
using DataFrames
using Periods

struct TimeDataFrame
    data::DataFrame
    continuous::Bool
    frequency::Periods.Frequency
end;

function TimeDataFrame(dataframe::AbstractDataFrame, frequency::Periods.Frequency, firstperiod)
    data = dataframe
    continuous = true
16
    data.Periods = [Period(firstperiod + i - 1, 0, Year) for i in 1:dataframe.nrow] 
Michel Juillard's avatar
Michel Juillard committed
17
18
19
    TimeDataFrame(dataframe, true, frequency) 
end

20
function TimeDataFrame(filename::String, frequency::Frequency, firstperiod)
Michel Juillard's avatar
Michel Juillard committed
21
22
    data = DataFrame(CSV.File(filename))
    continuous = true
23
    data.periods = [Period(firstperiod + i - 1, 0, Year) for i in 1:nrow(data)] 
Michel Juillard's avatar
Michel Juillard committed
24
25
26
27
    TimeDataFrame(data, true, frequency) 
end

end # module