polars.concat

polars.concat(items: Sequence[polars.internals.frame.DataFrame], rechunk: bool = True, how: str = 'vertical') polars.internals.frame.DataFrame
polars.concat(items: Sequence[polars.internals.series.Series], rechunk: bool = True, how: str = 'vertical') polars.internals.series.Series
polars.concat(items: Sequence[polars.internals.lazy_frame.LazyFrame], rechunk: bool = True, how: str = 'vertical') polars.internals.lazy_frame.LazyFrame

Aggregate all the Dataframes/Series in a List of DataFrames/Series to a single DataFrame/Series.

Parameters
items

DataFrames/Series/LazyFrames to concatenate.

rechunk

rechunk the final DataFrame/Series.

how

Only used if the items are DataFrames.

One of {“vertical”, “diagonal”, “horizontal”}.

  • 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.

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   │
└─────┴─────┘