1. Uczyć się
  2. /
  3. Courses
  4. /
  5. Data Transformation with Polars

Connected

Exercise

Creating reusable expressions

Now that you can transform columns, you want to understand which artists have a dedicated fanbase by calculating streams per listener. Rather than rewriting this formula each time, store the calculation as a Polars expression variable that you can reuse across multiple DataFrames.

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

Instrukcje

100 XP
  • Create an expression that divides streams by monthly_listeners.
  • Apply the expression variable and sort by streams_per_listener in descending order.