Building a correlation matrix
Now that you've ranked albums, the strategy team wants to understand which metrics move together. The Spotify dataset has been enriched with streams_billions and streams_per_listener columns. Build a correlation matrix to spot strong and weak relationships between these numeric features.
polars is loaded as pl. The DataFrame spotify with additional columns is preloaded for you.
Deze oefening maakt deel uit van de cursus
Data Transformation with Polars
Oefeninstructies
- Pick five numeric columns:
streams_billions,monthly_listeners,streams_per_listener,duration_ms, andpopularity, and compute the correlation. - Add a
metriccolumn to the result for better readability.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Build a correlation matrix from selected columns
corr = spotify.____(
"streams_billions",
"monthly_listeners",
"streams_per_listener",
"duration_ms",
"____",
).____()
# Add a metric column for row labels
result = corr.with_columns(pl.Series("____", corr.columns))
print(result)