Loading a time series from CSV into a DataFrame

78 views Asked by At

Is it possible to create a Daru DataFrame from a CSV in which the first column is a series of dates?

Take the following CSV, for instance:

time,min,max
2018-01-01,101,103
2018-01-02,102,105
2018-01-03,103,200
2018-01-04,104,109
2018-01-05,105,110

If loaded with Daru::DataFrame.from_csv it will create a 5x3 DataFrame with a 0-based numerical index, instead of a 5x2 DataFrame with a DateTimeIndex.

Is there a way to instruct Daru to use the first vector as a DateTimeIndex index?

1

There are 1 answers

0
kojix2 On BEST ANSWER
df = Daru::DataFrame.from_csv("df.csv")
df.set_index "time"
df.index = Daru::DateTimeIndex.new(df.index)
df
<Daru::DataFrame(5x2)>
                  min        max
2018-01-01        101        103
2018-01-02        102        105
2018-01-03        103        200
2018-01-04        104        109
2018-01-05        105        110