Melts
Melt operations unpivot a DataFrame from wide format to long format
Dataset
shape: (3, 4)
┌─────┬─────┬─────┬─────┐
│ A ┆ B ┆ C ┆ D │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╪═════╡
│ a ┆ 1 ┆ 10 ┆ 2 │
│ b ┆ 3 ┆ 11 ┆ 4 │
│ a ┆ 5 ┆ 12 ┆ 6 │
└─────┴─────┴─────┴─────┘
Eager + lazy
Eager
and lazy
have the same API.
out = df.melt(id_vars=["A", "B"], value_vars=["C", "D"])
print(out)
let out = df.melt(["A", "B"], ["C", "D"])?;
println!("{}", &out);
shape: (6, 4)
┌─────┬─────┬──────────┬───────┐
│ A ┆ B ┆ variable ┆ value │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str ┆ i64 │
╞═════╪═════╪══════════╪═══════╡
│ a ┆ 1 ┆ C ┆ 10 │
│ b ┆ 3 ┆ C ┆ 11 │
│ a ┆ 5 ┆ C ┆ 12 │
│ a ┆ 1 ┆ D ┆ 2 │
│ b ┆ 3 ┆ D ┆ 4 │
│ a ┆ 5 ┆ D ┆ 6 │
└─────┴─────┴──────────┴───────┘