Technical requirements
You can download the dataset and code from the GitHub repository:
- Dataset: https://github.com/PacktPublishing/Polars-Cookbook/tree/main/data
- Code: https://github.com/PacktPublishing/Polars-Cookbook/tree/main/Chapter08
It is assumed that you have installed the Polars library in your Python environment:
>>> pip install polars
And that you imported it in your code:
import polars as pl
We’ll be using the international student demographic dataset in this chapter. There are a few CSV files in the dataset we’ll be using, but academic.csv
will be used throughout the chapter. Read it into a DataFrame with the following code:
df = pl.read_csv('../data/academic.csv')
Clean the data by renaming a column, casting data types, and keeping only the recent years of data:
from polars import selectors as cs df = ( df .select( ...