1. Учиться
  2. /
  3. Courses
  4. /
  5. Data Transformation with Polars

Connected

Exercise

Adding a custom expression

Your team frequently calculates per-listener metrics across different reports. To make this pattern even more reusable, create a custom expression that can be chained like any built-in Polars method.

polars is loaded as pl. The DataFrame spotify is available with album streaming data.

Инструкции

100 XP
  • Define per_listener() to divide its input by the monthly_listeners column.
  • Attach the function to pl.Expr to make it chainable.
  • Apply the custom method on the streams column.