polars.LazyFrame.melt
-
Unpivot a DataFrame from wide to long format.
Optionally leaves identifiers set.
This function is useful to massage a DataFrame into a format where one or more columns are identifier variables (id_vars) while all other columns, considered measured variables (value_vars), are “unpivoted” to the row axis leaving just two non-identifier columns, ‘variable’ and ‘value’.
Deprecated since version 1.0.0: Use the
unpivot()method instead.- Parameters:
-
- id_vars
-
Column(s) or selector(s) to use as identifier variables.
- value_vars
-
Column(s) or selector(s) to use as values variables; if
value_varsis empty all columns that are not inid_varswill be used. - variable_name
-
Name to give to the
variablecolumn. Defaults to “variable” - value_name
-
Name to give to the
valuecolumn. Defaults to “value” - streamable
-
Allow this node to run in the streaming engine. If this runs in streaming, the output of the unpivot operation will not have a stable ordering.
LazyFrame.melt(
id_vars: ColumnNameOrSelector | Sequence[ColumnNameOrSelector] | None = None,
value_vars: ColumnNameOrSelector | Sequence[ColumnNameOrSelector] | None = None,
variable_name: str | None = None,
value_name: str | None = None,
*,
streamable: bool = True,
) → LazyFrame
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.melt.html