polars.concat#

polars.concat(items: Sequence[DataFrame], rechunk: bool = True, how: ConcatMethod = 'vertical', parallel: bool = True) DataFrame[source]#
polars.concat(items: Sequence[Series], rechunk: bool = True, how: ConcatMethod = 'vertical', parallel: bool = True) Series
polars.concat(items: Sequence[LazyFrame], rechunk: bool = True, how: ConcatMethod = 'vertical', parallel: bool = True) LazyFrame
polars.concat(items: Sequence[Expr], rechunk: bool = True, how: ConcatMethod = 'vertical', parallel: bool = True) Expr

Aggregate multiple Dataframes/Series to a single DataFrame/Series.

Parameters:
items

DataFrames/Series/LazyFrames to concatenate.

rechunk

Make sure that all data is in contiguous memory.

how{‘vertical’, ‘diagonal’, ‘horizontal’}

Only used if the items are DataFrames.

  • Vertical: applies multiple vstack operations.

  • Diagonal: finds a union between the column schemas and fills missing column

    values with null.

  • Horizontal: stacks Series horizontally and fills with nulls if the lengths

    don’t match.

parallel

Only relevant for LazyFrames. This determines if the concatenated lazy computations may be executed in parallel.

Examples

>>> df1 = pl.DataFrame({"a": [1], "b": [3]})
>>> df2 = pl.DataFrame({"a": [2], "b": [4]})
>>> pl.concat([df1, df2])
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 3   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 2   ┆ 4   │
└─────┴─────┘