Module: CArray::TableMethods

Defined in:
lib/carray-dataframe/converter.rb

Instance Method Summary collapse

Instance Method Details

#to_dataframe(index: nil, &block) ⇒ Object Also known as: to_df



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/carray-dataframe/converter.rb', line 4

def to_dataframe (index: nil, &block)
  if self.size == 0
    return nil
  end
  df = CADataFrame.new(self, index: index, &block)
  if @header or @note
    df.instance_variable_set(:@header, @header)
    df.instance_variable_set(:@note, @note)
    class << df
      attr_reader :note

      def header (name=nil)
        if name
          return @header[name.to_s]
        else
          return @column_names
        end
      end
    end
  end
  return df
end