Class: Rover::DataFrame
- Inherits:
-
Object
- Object
- Rover::DataFrame
- Defined in:
- lib/to_csv.rb
Instance Method Summary collapse
- #categorize(col) ⇒ Object
- #get_category(categ) ⇒ Object
-
#left_join_rev(other, on:) ⇒ Object
Roverのleft_joinをエラー回避.
- #map(&block) ⇒ Object
- #outer_join(other, **kwargs) ⇒ Object
- #simple_pivot(index, vectors) ⇒ Object
- #to_daru ⇒ Object
-
#write_csv(path, encoding: nil) ⇒ Object
Rover#to_csv is already exist.
Instance Method Details
#categorize(col) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/to_csv.rb', line 126 def categorize(col) if col.is_a?(Array) self[col].to_a.uniq else self[[col]].to_a.uniq end end |
#get_category(categ) ⇒ Object
134 135 136 137 138 |
# File 'lib/to_csv.rb', line 134 def get_category(categ) a = self[categ.each_key.to_a].to_a mask = a.filter_map.with_index {|v, i| i if v == categ } return self[mask] end |
#left_join_rev(other, on:) ⇒ Object
Roverのleft_joinをエラー回避
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/to_csv.rb', line 141 def left_join_rev(other, on:) left_rows = self.to_a right_rows = other.to_a right_map = right_rows.each_with_object({}) do |row, map| map[row[on]] = row end result_rows = [] left_rows.each do |l_row| key = l_row[on] r_row = right_map[key] if r_row result_rows << l_row.merge(r_row) else result_rows << l_row end end Rover::DataFrame.new(result_rows) end |
#map(&block) ⇒ Object
122 123 124 |
# File 'lib/to_csv.rb', line 122 def map(&block) self.to_a.map(&block) end |
#outer_join(other, **kwargs) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/to_csv.rb', line 115 def outer_join(other, **kwargs) ddr = self.to_daru odr = self.to_daru j = ddr.join(how: :outer, **kwargs) ## 外部結合 return j.to_rover end |
#simple_pivot(index, vectors) ⇒ Object
109 110 111 112 113 |
# File 'lib/to_csv.rb', line 109 def simple_pivot(index, vectors, ...) ddr = self.to_daru piv = ddr.simple_pivot(index, vectors, ...) return piv.to_rover end |
#to_daru ⇒ Object
105 106 107 |
# File 'lib/to_csv.rb', line 105 def to_daru Daru::DataFrame.new(self.to_a) end |
#write_csv(path, encoding: nil) ⇒ Object
Rover#to_csv is already exist.
100 101 102 103 |
# File 'lib/to_csv.rb', line 100 def write_csv(path, encoding: nil) enc = encoding.nil? ? "" : ":#{encoding}" open(path, "w#{enc}") {|f| f.write self.to_csv} end |