polars.DataFrame.extend#
- DataFrame.extend(other: DataFrame) Self[source]#
Extend the memory backed by this
DataFramewith the values fromother.Different from
vstackwhich adds the chunks fromotherto the chunks of thisDataFrame,extendappends the data fromotherto the underlying memory locations and thus may cause a reallocation.If this does not cause a reallocation, the resulting data structure will not have any extra chunks and thus will yield faster queries.
Prefer
extendovervstackwhen you want to do a query after a single append. For instance, during online operations where you addnrows and rerun a query.Prefer
vstackoverextendwhen you want to append many times before doing a query. For instance, when you read in multiple files and want to store them in a singleDataFrame. In the latter case, finish the sequence ofvstackoperations with arechunk.- Parameters:
- other
DataFrame to vertically add.
Warning
This method modifies the dataframe in-place. The dataframe is returned for convenience only.
See also
Examples
>>> df1 = pl.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]}) >>> df2 = pl.DataFrame({"foo": [10, 20, 30], "bar": [40, 50, 60]}) >>> df1.extend(df2) shape: (6, 2) ┌─────┬─────┐ │ foo ┆ bar │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 1 ┆ 4 │ │ 2 ┆ 5 │ │ 3 ┆ 6 │ │ 10 ┆ 40 │ │ 20 ┆ 50 │ │ 30 ┆ 60 │ └─────┴─────┘