Class: PhillyFrbAsDataframe::SurveyProfForecasters
- Inherits:
-
Object
- Object
- PhillyFrbAsDataframe::SurveyProfForecasters
- Includes:
- HTTParty
- Defined in:
- lib/philly_frb_as_dataframe/survey_prof_forecasters.rb
Instance Attribute Summary collapse
-
#ary ⇒ Object
readonly
Returns the value of attribute ary.
Instance Method Summary collapse
- #fetch(start: nil, fin: nil) ⇒ Object
-
#initialize ⇒ SurveyProfForecasters
constructor
A new instance of SurveyProfForecasters.
Constructor Details
#initialize ⇒ SurveyProfForecasters
Returns a new instance of SurveyProfForecasters.
13 14 |
# File 'lib/philly_frb_as_dataframe/survey_prof_forecasters.rb', line 13 def initialize end |
Instance Attribute Details
#ary ⇒ Object (readonly)
Returns the value of attribute ary.
11 12 13 |
# File 'lib/philly_frb_as_dataframe/survey_prof_forecasters.rb', line 11 def ary @ary end |
Instance Method Details
#fetch(start: nil, fin: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/philly_frb_as_dataframe/survey_prof_forecasters.rb', line 16 def fetch(start: nil, fin: nil) dat = _fetch_data.dup hsh = dat.map{|d| d.map{|r| r.to_hash }.each{|h| h['Timestamps_'] = Date.new(h['YEAR'], (3*(h['QUARTER'])-2), 1) } } df = nil hsh.each do |h| keys = h.first.keys vals = h.map(&:values).transpose tmp_df = {}; (0..(keys.length-1)).to_a.each{|i| tmp_df[keys[i]] = vals[i]} tmp_df = Polars::DataFrame.new(tmp_df).drop(['QUARTER', 'YEAR']) tmp_df = tmp_df.filter(Polars.col('Timestamps_') <= fin.to_date) unless start.nil? tmp_df = tmp_df.filter(Polars.col('Timestamps_') >= start.to_date) unless fin.nil? if h == hsh.first df = tmp_df else df = df.join(tmp_df, on: 'Timestamps_', how: 'full').drop(['Timestamps__right']) end end s = Polars::Series.new('Timestamps', df['Timestamps_'].to_a) df = df.insert_column(0,s).drop(['Timestamps_']) df end |