BaşlayınÜcretsiz Başlayın

Ranking albums with tie handling

Your record company publishes an internal leaderboard each week based on the Spotify dataset. Tie handling can change how artists are perceived - several albums share the same listener counts, so you need to compare how different ranking methods handle ties.

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

Bu egzersiz

Data Transformation with Polars

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a ranking of monthly_listeners in descending order, aliasing as rank_default.
  • Add a second ranking with leaderboard-style tie handling, aliasing as rank_min.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Rank albums by monthly_listeners with default and min tie handling
result = spotify.with_columns(
    pl.col("monthly_listeners")
    .____(descending=____)
    .alias("rank_default"),

    pl.col("monthly_listeners")
    .rank(method="____", ____=True)
    .alias("rank_min"),
).sort("rank_default")

print(result.head())
Kodu Düzenle ve Çalıştır