Class: Daru::IO::Importers::Excel
- Defined in:
- lib/daru/io/importers/excel.rb
Overview
Excel Importer Class, that extends read_excel
method to Daru::DataFrame
Class Method Summary collapse
-
.read(path) ⇒ Daru::IO::Importers::Excel
Reads from an excel (.xls) file.
Instance Method Summary collapse
-
#call(worksheet_id: 0, headers: true) ⇒ Daru::DataFrame
Imports a
Daru::DataFrame
from an Excel Importer instance. -
#initialize ⇒ Excel
constructor
Checks for required gem dependencies of Excel Importer.
-
#read(path) ⇒ Daru::IO::Importers::Excel
Reads from an excel (.xls) file.
Methods inherited from Base
Methods inherited from Base
Constructor Details
#initialize ⇒ Excel
Checks for required gem dependencies of Excel Importer
20 21 22 |
# File 'lib/daru/io/importers/excel.rb', line 20 def initialize optional_gem 'spreadsheet', '~> 1.1.1' end |
Class Method Details
.read(path) ⇒ Daru::IO::Importers::Excel
Reads from an excel (.xls) file
34 35 36 37 |
# File 'lib/daru/io/importers/excel.rb', line 34 def read(path) @file_data = Spreadsheet.open(path) self end |
Instance Method Details
#call(worksheet_id: 0, headers: true) ⇒ Daru::DataFrame
Imports a Daru::DataFrame
from an Excel Importer instance
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/daru/io/importers/excel.rb', line 79 def call(worksheet_id: 0, headers: true) worksheet = @file_data.worksheet(worksheet_id) headers = if headers ArrayHelper.recode_repeated(worksheet.row(0)).map(&:to_sym) else (0..worksheet.row(0).to_a.size-1).to_a end df = Daru::DataFrame.new({}) headers.each_with_index do |h,i| col = worksheet.column(i).to_a col.delete_at(0) if headers df[h] = col end df end |
#read(path) ⇒ Daru::IO::Importers::Excel
Reads from an excel (.xls) file
34 35 36 37 |
# File 'lib/daru/io/importers/excel.rb', line 34 def read(path) @file_data = Spreadsheet.open(path) self end |