Module: DaruLite::DataFrame::IOAble
- Included in:
- DaruLite::DataFrame
- Defined in:
- lib/daru_lite/data_frame/i_o_able.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #_dump(_depth) ⇒ Object
-
#save(filename) ⇒ Object
Use marshalling to save dataframe to a file.
-
#write_csv(filename, opts = {}) ⇒ Object
Write this DataFrame to a CSV file.
-
#write_excel(filename, opts = {}) ⇒ Object
Write this dataframe to an Excel Spreadsheet.
-
#write_sql(arh, table) ⇒ Object
Insert each case of the Dataset on the selected table.
Class Method Details
.included(base) ⇒ Object
121 122 123 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 121 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#_dump(_depth) ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 172 def _dump(_depth) Marshal.dump( data: @data, index: @index.to_a, order: @vectors.to_a, name: @name ) end |
#save(filename) ⇒ Object
Use marshalling to save dataframe to a file.
168 169 170 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 168 def save(filename) DaruLite::IO.save self, filename end |
#write_csv(filename, opts = {}) ⇒ Object
Write this DataFrame to a CSV file.
Arguments
-
filename - Path of CSV file where the DataFrame is to be saved.
Options
-
convert_comma - If set to true, will convert any commas in any
of the data to full stops (‘.’). All the options accepted by CSV.read() can also be passed into this function.
137 138 139 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 137 def write_csv(filename, opts = {}) DaruLite::IO.dataframe_write_csv self, filename, opts end |
#write_excel(filename, opts = {}) ⇒ Object
Write this dataframe to an Excel Spreadsheet
Arguments
-
filename - The path of the file where the DataFrame should be written.
146 147 148 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 146 def write_excel(filename, opts = {}) DaruLite::IO.dataframe_write_excel self, filename, opts end |
#write_sql(arh, table) ⇒ Object
Insert each case of the Dataset on the selected table
Arguments
-
arh - ActiveRecord database connection object.
-
query - Query string.
Usage
ds = DaruLite::DataFrame.new({:id=>DaruLite::Vector.new([1,2,3]), :name=>DaruLite::Vector.new(["a","b","c"])})
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "path/to/sqlite.db")
arh = ActiveRecord::Base.connection
ds.write_sql(arh,"test")
163 164 165 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 163 def write_sql(arh, table) DaruLite::IO.dataframe_write_sql self, arh, table end |