Sha256: 77e8218e2ba7562043c7aaf626f9fb2930017206b6aacc407d1fe3c851e4450a

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

module Daru
  module IO
    class << self
      def from_csv path, opts={}
        opts[:col_sep]           ||= ','
        opts[:headers]           ||= true
        opts[:converters]        ||= :numeric
        opts[:header_converters] ||= :symbol

        csv = CSV.open(path, 'r', opts)

        yield csv if block_given?

        first = true
        df    = nil

        csv.each_with_index do |row, index|
          if first
            df    = Daru::DataFrame.new({}, csv.headers)
            first = false
          end

          df.row[index] = row.fields
        end

        df
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daru-0.0.3 lib/daru/io.rb