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(dbh, table) ⇒ Object
Insert each case of the Dataset on the selected table.
Class Method Details
.included(base) ⇒ Object
119 120 121 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 119 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#_dump(_depth) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 169 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.
165 166 167 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 165 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.
135 136 137 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 135 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.
144 145 146 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 144 def write_excel(filename, opts = {}) DaruLite::IO.dataframe_write_excel self, filename, opts end |
#write_sql(dbh, table) ⇒ Object
Insert each case of the Dataset on the selected table
Arguments
-
dbh - DBI 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"])})
dbh = DBI.connect("DBI:Mysql:database:localhost", "user", "password")
ds.write_sql(dbh,"test")
160 161 162 |
# File 'lib/daru_lite/data_frame/i_o_able.rb', line 160 def write_sql(dbh, table) DaruLite::IO.dataframe_write_sql self, dbh, table end |