1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Polars

Connected

Exercise

Pivoting a DataFrame

You want to convert the Spotify data from long format to wide format in order to compare the number of streams for each artist in each year.

The spotify_df DataFrame is available for you and has been modified to get the number of streams for each artist in each year in artist_year_df.

Instructions 1/2

undefined XP
  • 1
    • Pivot artist_year_df to get the "artist" on each row, the "year" for each column, and the "streams" values.
  • 2
    • Pivot spotify_df directly where we aggregate by calculating the mean number of streams per artist per year.