Interface DataFrameConstructor

DataFrame constructor

interface DataFrameConstructor {
    deserialize(buf, format): pl.DataFrame;
    isDataFrame(arg): arg is pl.DataFrame;
    (): pl.DataFrame;
    (data, options?): pl.DataFrame;
}

Hierarchy

  • Create an empty DataFrame

    Returns pl.DataFrame

  • Create a DataFrame from a JavaScript object

    Parameters

    • data: any

      object or array of data

    • Optional options: {
          columns?: any[];
          inferSchemaLength?: number;
          orient?: "row" | "col";
          schema?: Record<string, string | DataType>;
          schemaOverrides?: Record<string, string | DataType>;
      }

      options

      • Optional columns?: any[]

        column names

      • Optional inferSchemaLength?: number

        The maximum number of rows to scan for schema inference. If set to None, the full data may be scanned (this can be slow). This parameter only applies if the input data is a sequence or generator of rows; other input is read as-is. The number of entries in the schema should match the underlying data dimensions, unless a sequence of dictionaries is being passed, in which case a partial schema can be declared to prevent specific fields from being loaded.

      • Optional orient?: "row" | "col"

        orientation of the data [row, col] Whether to interpret two-dimensional data as columns or as rows. If None, the orientation is inferred by matching the columns and data dimensions. If this does not yield conclusive results, column orientation is used.

      • Optional schema?: Record<string, string | DataType>

        The schema of the resulting DataFrame. The schema may be declared in several ways:

        - As a dict of {name:type} pairs; if type is None, it will be auto-inferred.

        - As a list of column names; in this case types are automatically inferred.

        - As a list of (name,type) pairs; this is equivalent to the dictionary form.

        If you supply a list of column names that does not match the names in the underlying data, the names given here will overwrite them. The number of names given in the schema should match the underlying data dimensions.

        If set to null (default), the schema is inferred from the data.

      • Optional schemaOverrides?: Record<string, string | DataType>

        Support type specification or override of one or more columns; note that any dtypes inferred from the schema param will be overridden.

    Returns pl.DataFrame

    Example

    data = {'a': [1n, 2n], 'b': [3, 4]}
    df = pl.DataFrame(data)
    df
    shape: (2, 2)
    ╭─────┬─────╮
    ab
    │ --- ┆ --- │
    u64i64
    ╞═════╪═════╡
    13
    ├╌╌╌╌╌┼╌╌╌╌╌┤
    24
    ╰─────┴─────╯

Methods