建立熱門度直方圖
你已經計算過分位數並完成分箱,現在把整體熱門度分佈視覺化,讓分析更完整。Spotify 資料集中的 popularity 欄位範圍是 0 到 100。請用自訂箱邊界建立直方圖計數,接著用 Plotly 繪製分佈,看看多數專輯集中在哪裡。
polars 已載入為 pl,plotly.express 已載入為 px。DataFrame spotify 可供使用。
本練習屬於課程
使用 Polars 進行資料轉換
練習說明
- 以
popularity建立直方圖計數,箱邊界設為 0、25、50、75、100。 - 建立長條圖,x 軸使用
category,y 軸使用count。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Build histogram counts with custom bins
hist = spotify["popularity"].____(bins=[0, 25, 50, ____, ____])
# Create a bar chart of the distribution
fig = px.____(hist, x="____", y="____")
fig.show()