LoslegenKostenlos starten

Calculating popularity quantiles

You're continuing to analyze the Spotify dataset containing 25 popular albums with metrics like streams, monthly_listeners, and popularity. The marketing team needs clear tiers for underperforming, typical, and breakout albums. Calculate percentiles to help the team understand how popularity is distributed.

polars is loaded as pl. The DataFrame spotify with streaming metrics is preloaded for you.

Diese Übung ist Teil des Kurses

<Kurs>Data Transformation with Polars</Kurs>
Kurs ansehen

Übungsanweisungen

  • Select the popularity column and calculate the 25th percentile, aliasing it as q25_popularity.
  • Add the 50th and 75th percentiles to the appropriate aliases.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Calculate the 25th, 50th, and 75th percentiles of popularity
result = spotify.select(
    pl.col("____").____(0.25).alias("q25_popularity"),
    pl.col("popularity").quantile(____).alias("q50_popularity"),
    pl.col("popularity").quantile(____).alias("q75_popularity"),
)

print(result)
Code bearbeiten und ausführen