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をエラー回避.
- #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
121 122 123 124 125 126 127 |
# File 'lib/to_csv.rb', line 121 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
129 130 131 132 133 |
# File 'lib/to_csv.rb', line 129 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をエラー回避
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/to_csv.rb', line 136 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 |
#outer_join(other, **kwargs) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/to_csv.rb', line 114 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
108 109 110 111 112 |
# File 'lib/to_csv.rb', line 108 def simple_pivot(index, vectors, ...) ddr = self.to_daru piv = ddr.simple_pivot(index, vectors, ...) return piv.to_rover end |
#to_daru ⇒ Object
104 105 106 |
# File 'lib/to_csv.rb', line 104 def to_daru Daru::DataFrame.new(self.to_a) end |
#write_csv(path, encoding: nil) ⇒ Object
Rover#to_csv is already exist.
99 100 101 102 |
# File 'lib/to_csv.rb', line 99 def write_csv(path, encoding: nil) enc = encoding.nil? ? "" : ":#{encoding}" open(path, "w#{enc}") {|f| f.write self.to_csv} end |