Convert DataFrame to a Series of type "struct"
Description
Convert DataFrame to a Series of type "struct"
Usage
<DataFrame>$to_struct(name = "")
Arguments
name
|
Name given to the new Series |
Value
A Series of type "struct"
Examples
library("polars")
# round-trip conversion from DataFrame with two columns
df = pl$DataFrame(a = 1:5, b = c("one", "two", "three", "four", "five"))
s = df$to_struct()
s
#> polars Series: shape: (5,)
#> Series: '' [struct[2]]
#> [
#> {1,"one"}
#> {2,"two"}
#> {3,"three"}
#> {4,"four"}
#> {5,"five"}
#> ]
#> $a
#> [1] 1 2 3 4 5
#>
#> $b
#> [1] "one" "two" "three" "four" "five"
#>
#> attr(,"is_struct")
#> [1] TRUE
#> shape: (5, 1)
#> ┌─────────────┐
#> │ │
#> │ --- │
#> │ struct[2] │
#> ╞═════════════╡
#> │ {1,"one"} │
#> │ {2,"two"} │
#> │ {3,"three"} │
#> │ {4,"four"} │
#> │ {5,"five"} │
#> └─────────────┘