開始使用免費開始

建立熱門度直方圖

你已經計算過分位數並完成分箱,現在把整體熱門度分佈視覺化,讓分析更完整。Spotify 資料集中的 popularity 欄位範圍是 0 到 100。請用自訂箱邊界建立直方圖計數,接著用 Plotly 繪製分佈,看看多數專輯集中在哪裡。

polars 已載入為 plplotly.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()
編輯並執行程式碼