Module: DF::Import::ClassMethods
Overview
InferCSV
Instance Method Summary collapse
-
#from_csv(obj, opts = {}) ⇒ Object
This is the neatest part of this neat gem.
Instance Method Details
#from_csv(obj, opts = {}) ⇒ Object
This is the neatest part of this neat gem. DataFrame.from_csv can be called in a lot of ways: DataFrame.from_csv(csv_contents) DataFrame.from_csv(filename) DataFrame.from_csv(url) If you need to define converters for FasterCSV, do it before calling this method: FasterCSV::Converters = lambda{|f| f == ‘foo’ ? ‘bar’ : ‘foo’} DataFrame.from_csv(‘example.com/my_special_url.csv’, :converters => :special) This returns bar where ‘foo’ was found and ‘foo’ everywhere else.
42 43 44 45 46 47 48 49 50 |
# File 'lib/data_frame/core/import.rb', line 42 def from_csv(obj, opts={}) labels, table = infer_csv_contents(obj, opts) name = infer_name_from_contents(obj, opts) return nil unless labels and table df = new(*labels) df.import(table) df.name = name df end |