開始使用免費開始

計算數值出現次數

你想了解在 Spotify 資料集中,哪些歌手擁有最多歌曲。讓我們來統計每位歌手的歌曲數量,並將結果視覺化。

已提供 spotify_df DataFrame,且已將 Plotly Express 以 px 匯入。

本練習屬於課程

Polars 入門

檢視課程

練習說明

  • "artist" 欄使用 .value_counts() 來計算每位歌手的歌曲數量,並將輸出排序。
  • 使用 Plotly Express 建立長條圖以視覺化這些計數。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Count songs per artist
artist_counts = spotify_df["artist"].____

# Create a bar plot
fig = px.bar(____, x=____, y=____, title="Number of Songs per Artist")

fig.show()
編輯並執行程式碼