Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/docs/source/src/python/user-guide/transformations/unpivot.py
7890 views
1
# --8<-- [start:df]
2
import polars as pl
3
4
df = pl.DataFrame(
5
{
6
"A": ["a", "b", "a"],
7
"B": [1, 3, 5],
8
"C": [10, 11, 12],
9
"D": [2, 4, 6],
10
}
11
)
12
print(df)
13
# --8<-- [end:df]
14
15
# --8<-- [start:unpivot]
16
out = df.unpivot(["C", "D"], index=["A", "B"])
17
print(out)
18
# --8<-- [end:unpivot]
19
20