Module: Polars::Convert

Included in:
Polars
Defined in:
lib/polars/convert.rb

Instance Method Summary collapse

Instance Method Details

#from_hash(data, schema: nil, columns: nil) ⇒ DataFrame

Construct a DataFrame from a dictionary of sequences.

This operation clones data, unless you pass in a Hash<String, Series>.

Examples:

data = {"a" => [1, 2], "b" => [3, 4]}
Polars.from_hash(data)
# =>
# shape: (2, 2)
# ┌─────┬─────┐
# │ a   ┆ b   │
# │ --- ┆ --- │
# │ i64 ┆ i64 │
# ╞═════╪═════╡
# │ 1   ┆ 3   │
# │ 2   ┆ 4   │
# └─────┴─────┘

Parameters:

  • data (Hash)

    Two-dimensional data represented as a hash. Hash must contain arrays.

  • columns (Array) (defaults to: nil)

    Column labels to use for resulting DataFrame. If specified, overrides any labels already present in the data. Must match data dimensions.

Returns:



29
30
31
32
33
34
35
36
# File 'lib/polars/convert.rb', line 29

def from_hash(data, schema: nil, columns: nil)
  Utils.wrap_df(
    DataFrame.hash_to_rbdf(
      data,
      schema: schema || columns
    )
  )
end