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.
Deze oefening maakt deel uit van de cursus
Introduction to Polars
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
artist_year_df = spotify_df.group_by("artist", "year").agg(pl.col("streams").sum())
pivoted_df = (
artist_year_df
# Pivot with artists as rows, years as columns and streams as values
.pivot(
on=____,
index=____,
values=____
)
)
print(pivoted_df)