require 'daru' require 'awesome_print' # In the code below we will create a DateTimeIndex starting from 2012-4-4 to 2012-4-19 # with a daily frequency. The 'D' supplied to the :freq argument specifies that frequency # has to be daily. It can be any of the string offset alaises amongst those supported. See # the section below for a complete overview of date offsets. index = Daru::DateTimeIndex.date_range(:start => '2012-4-4', :end => '2012-4-19', :freq => 'D') ap index.to_a nil # The following code will create a range between 2014-5-1 00:00:00 and 2014,5,2 00:00:00, # with a difference of 6 hours between each date. index = Daru::DateTimeIndex.date_range(:start => DateTime.new(2014,5,1), :end => DateTime.new(2014,5,2), :freq => '6H') ap index.to_a; nil offset = Daru::Offsets::Second.new(6) index = Daru::DateTimeIndex.date_range(:start => '2012-5-6', :end => '2012-5-6 20:00:00', :freq => offset) index = Daru::DateTimeIndex.date_range(:start => '2012-5-2', :periods => 50, :freq => 'ME') index.frequency index = Daru::DateTimeIndex.new( [DateTime.new(2012,4,5), DateTime.new(2012,4,6), DateTime.new(2012,4,7), DateTime.new(2012,4,8)]) index = Daru::DateTimeIndex.new([ DateTime.new(2012,4,5), DateTime.new(2012,4,6), DateTime.new(2012,4,7), DateTime.new(2012,4,8), DateTime.new(2012,4,9), DateTime.new(2012,4,10), DateTime.new(2012,4,11), DateTime.new(2012,4,12) ], freq: :infer) index = Daru::DateTimeIndex.date_range(:start => '2012', :periods => 10, :freq => 'YEAR') index.year index.shift(Daru::Offsets::Hour.new(3)) index.shift(4) # Shift by 4 years index.lag(Daru::DateOffset.new(days: 4)) index.lag(2) index = Daru::DateTimeIndex.date_range(:start => '2012-3-4', :periods => 50000, :freq => 'H') vector = Daru::Vector.new([1,2,3,4,5]*10000, index: index) vector.head vector['2012-4'] vector['2013'] vector['2013-2-4'] vector['2013-2-4 22'] vector[DateTime.new(2012,5,1)] index = Daru::DateTimeIndex.date_range(:start => '2012-4-5', :periods => 50, :freq => 'D') df = Daru::DataFrame.new({ a: [1,2,3,4,5]*10, b: ['a','b','c','d','e']*10, c: ['foo', 'bar','baz','razz','jazz']*10 }, index: index) df.row['2012-5']