人気度のパーセンタイルを計算する
streams、monthly_listeners、popularity などの指標を含む、人気アルバム25件の Spotify データセットを引き続き分析します。マーケティングチームは、低調・標準・ブレイクの明確な層分けを求めています。人気度の分布を把握できるよう、パーセンタイルを計算しましょう。
polars は pl として読み込まれており、ストリーミング指標を持つ DataFrame spotify はあらかじめ用意されています。
この演習はコースの一部です
Data Transformation with Polars
演習の手順
popularity列を選択し、25パーセンタイルを計算してq25_popularityという別名を付けます。- 50パーセンタイルと 75パーセンタイルも計算し、適切な別名を付けて追加します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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)