Class: PhillyFrbAsDataframe::PartisanConflict
- Inherits:
-
Object
- Object
- PhillyFrbAsDataframe::PartisanConflict
- Includes:
- HTTParty
- Defined in:
- lib/philly_frb_as_dataframe/partisan_conflict.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 ⇒ PartisanConflict
constructor
A new instance of PartisanConflict.
Constructor Details
#initialize ⇒ PartisanConflict
Returns a new instance of PartisanConflict.
13 14 |
# File 'lib/philly_frb_as_dataframe/partisan_conflict.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/partisan_conflict.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 |
# File 'lib/philly_frb_as_dataframe/partisan_conflict.rb', line 16 def fetch(start: nil, fin: nil) dat = _fetch_data.dup hsh = dat.map{|r| r.to_hash }.each{|h| h['Timestamps_'] = DateTime.strptime("#{h['Month']} 01 #{h['Year']}", '%B %d %Y').to_date } keys = hsh.first.keys vals = hsh.map(&:values).transpose df = {}; (0..(keys.length-1)).to_a.each{|i| df[keys[i]] = vals[i]} df = Polars::DataFrame.new(df) df = df.filter(Polars.col('Timestamps_') <= fin.to_date) unless start.nil? df = df.filter(Polars.col('Timestamps_') >= start.to_date) unless fin.nil? s = Polars::Series.new('Timestamps', df['Timestamps_'].to_a) df = df.insert_column(0,s).drop(['Month', 'Year', 'Timestamps_']) df end |