There are basically 2 ways to do this.
- Use .to_series() on .select() method on your polars dataframe.
- Use .to_series() alone. And you specify the index of your column to return. The first column by default.
- Choose a specific column like you do in pandas, with code like this: df[‘Your Column’]
Some may think that df.select(‘Your Column’) alone would work but nope. It doesn’t return a series object, it returns a dataframe object instead.
import polars as pl
# creating dummy data
data = [[1, 2, 3], ['A', 'B', 'C'], [111, 222, 333]]
df = pl.DataFrame(data, schema=['ID', 'Letter', 'Values'])
print(type(df))
# 1. using .to_series() on .select()
series_1 = df.select('ID').to_series()
print(type(series_1))
# 2. using .to_series() alone, column index specified
series_2 = df.to_series(2)
print(type(series_2))
# 3. just taking a column as a series
series_3 = df['ID']
print(type(series_3))
# .select() itself returns a dataframe
this_is_df = df.select('ID')
print(type(this_is_df))
Source code: Github repo