import polars as pl
import turtle_island as ti
= pl.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"], "c": [4.4, 5.5, 6.6]})
df df
a | b | c |
---|---|---|
i64 | str | f64 |
1 | "x" | 4.4 |
2 | "y" | 5.5 |
3 | "z" | 6.6 |
Returns a list of Polars expressions that reorder columns so the specified columns appear first.
You may specify either column names or data types, but not a combination of both.
columns : str | PolarsDataType | Collection[str] | Collection[PolarsDataType]
The name or datatype of the column(s) to move. Accepts regular expression input. Regular expressions should start with ^
and end with $
.
*more_columns : str | PolarsDataType = ()
Additional names or datatypes of columns to move, specified as positional arguments.
: list[pl.Expr]
A list of expressions to reorder columns.
select()
Context
The list of expressions returned by move_cols_to_start()
take effect only within the select()
context. Using them in with_columns()
will have no effect, and the result will remain unchanged.
a | b | c |
---|---|---|
i64 | str | f64 |
1 | "x" | 4.4 |
2 | "y" | 5.5 |
3 | "z" | 6.6 |
Reorder columns so that selected columns appear first:
Reorder by data type:
b | c | a |
---|---|---|
str | f64 | i64 |
"x" | 4.4 | 1 |
"y" | 5.5 | 2 |
"z" | 6.6 | 3 |
Note that when selecting by data type, the moved columns will follow the original order in the DataFrame schema.