Skip to content

Select column as Series at index location

Description

Select column as Series at index location

Usage

<DataFrame>$to_series(index = 0)

Arguments

index Index of the column to return as Series. Defaults to 0, which is the first column.

Value

Series or NULL

Examples

library("polars")

df <- as_polars_df(iris[1:10, ])

# default is to extract the first column
df$to_series()
#> shape: (10,)
#> Series: 'Sepal.Length' [f64]
#> [
#>  5.1
#>  4.9
#>  4.7
#>  4.6
#>  5.0
#>  5.4
#>  4.6
#>  5.0
#>  4.4
#>  4.9
#> ]
# Polars is 0-indexed, so we use index = 1 to extract the *2nd* column
df$to_series(index = 1)
#> shape: (10,)
#> Series: 'Sepal.Width' [f64]
#> [
#>  3.5
#>  3.0
#>  3.2
#>  3.1
#>  3.6
#>  3.9
#>  3.4
#>  3.4
#>  2.9
#>  3.1
#> ]