Sha256: c5f086d57370ce4937a660421b4beebbaebddaa1203ff0b31492d70e7987ebea

Contents?: true

Size: 772 Bytes

Versions: 15

Compression:

Stored size: 772 Bytes

Contents

module RbbtPython
  def self.py2ruby_a(array)
    PyCall::List.(array).to_a
  end

  class << self
    alias to_a py2ruby_a 
  end


  def self.tsv2df(tsv)
    df = nil
    RbbtPython.run 'pandas' do
      df = pandas.DataFrame.new(tsv.values, columns: tsv.fields, index: tsv.keys)
      df.columns.name = tsv.key_field
    end
    df
  end

  def self.df2tsv(tuple, options = {})
    options = Misc.add_defaults options, :type => :list
    IndiferentHash.setup options
    tsv = TSV.setup({}, options)
    tsv.key_field = options[:key_field] || tuple.columns.name
    tsv.fields = py2ruby_a(tuple.columns.values)
    keys = tuple.index.values
    PyCall.len(tuple.index).times do |i|
      k = keys[i]
      tsv[k] = py2ruby_a(tuple.values[i])
    end
    tsv
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rbbt-util-5.35.1 lib/rbbt/util/python/util.rb
rbbt-util-5.34.27 lib/rbbt/util/python/util.rb
rbbt-util-5.34.26 lib/rbbt/util/python/util.rb
rbbt-util-5.34.25 lib/rbbt/util/python/util.rb
rbbt-util-5.34.24 lib/rbbt/util/python/util.rb
rbbt-util-5.34.23 lib/rbbt/util/python/util.rb
rbbt-util-5.34.22 lib/rbbt/util/python/util.rb
rbbt-util-5.34.21 lib/rbbt/util/python/util.rb
rbbt-util-5.34.20 lib/rbbt/util/python/util.rb
rbbt-util-5.34.18 lib/rbbt/util/python/util.rb
rbbt-util-5.34.17 lib/rbbt/util/python/util.rb
rbbt-util-5.34.16 lib/rbbt/util/python/util.rb
rbbt-util-5.34.15 lib/rbbt/util/python/util.rb
rbbt-util-5.34.14 lib/rbbt/util/python/util.rb
rbbt-util-5.34.13 lib/rbbt/util/python/util.rb