Class: Remi::Parser::CsvFile
- Inherits:
-
Remi::Parser
- Object
- Remi::Parser
- Remi::Parser::CsvFile
- Includes:
- DataSubject::CsvFile
- Defined in:
- lib/remi/data_subjects/csv_file.rb
Overview
CsvFile parser
Instance Attribute Summary collapse
-
#csv_options ⇒ Hash
readonly
Csv options hash.
Attributes inherited from Remi::Parser
#context, #field_symbolizer, #fields, #logger
Instance Method Summary collapse
-
#initialize(*args, **kargs, &block) ⇒ CsvFile
constructor
A new instance of CsvFile.
-
#parse(data) ⇒ Remi::DataFrame
Converts a list of filenames into a dataframe after parsing them according ot the csv options that were set.
Constructor Details
#initialize(*args, **kargs, &block) ⇒ CsvFile
Returns a new instance of CsvFile.
59 60 61 62 |
# File 'lib/remi/data_subjects/csv_file.rb', line 59 def initialize(*args, **kargs, &block) super init_csv_file(*args, **kargs, &block) end |
Instance Attribute Details
#csv_options ⇒ Hash (readonly)
Returns Csv options hash.
65 66 67 |
# File 'lib/remi/data_subjects/csv_file.rb', line 65 def @csv_options end |
Instance Method Details
#parse(data) ⇒ Remi::DataFrame
Converts a list of filenames into a dataframe after parsing them according ot the csv options that were set
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/remi/data_subjects/csv_file.rb', line 71 def parse(data) # Assumes that each file has exactly the same structure result_df = nil Array(data).each_with_index do |filename, idx| filename = filename.to_s logger.info "Converting #{filename} to a dataframe" processed_filename = preprocess(filename) csv_df = Daru::DataFrame.from_csv processed_filename, @csv_options csv_df[@filename_field] = Daru::Vector.new([filename] * csv_df.size, index: csv_df.index) if @filename_field if idx == 0 result_df = csv_df else result_df = result_df.concat csv_df end end Remi::DataFrame.create(:daru, result_df) end |