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

Connected

Exercise

Unpivoting Data from Wide to Long Format

You've done a groupby-aggregation on the Spotify data that gives you a range of statistics on the number of streams per artist per year in the DataFrame wide_df. You now want to convert the data in wide_df to long format for use in a data visualization.

Instructions

100 XP
  • Use the "artist" and "year" as the index columns to identify the data on each row.
  • Unpivot on the statistics columns in wide_df: "avg_streams", "max_streams", "min_streams".
  • Name the variable column as "metric" and the value column as "stream_count".