Get startedGet started for free

How danceable are songs these days?

It's time to dive deeper into the Spotify data to analyze some trends in music.

In each CSV file, the 'danceability' column contains the score between 0 and 1 of how danceable each song is. The score describes how suitable a track is for dancing based on a combination of musical elements, including tempo, rhythm stability, beat strength, and overall regularity. Do you think songs are getting better or worse to dance to?

dask and the delayed() function have been imported for you. pandas has been imported as pd, and matplotlib.pyplot has been imported as plt. The list of filenames is available in your environment as filenames, and the year of each file is stored in the years list.

This exercise is part of the course

Parallel Programming with Dask in Python

View Course

Exercise instructions

  • Inside the loop, lazily load in each file.
  • Using the 'danceability' column, find the mean danceability of songs in each file.
  • Compute all of the results in the danceabilities list, and select the first item of the resulting tuple.
  • Make a plot with danceability_list on the y-axis and years on the x-axis using plt.plot().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

danceabilities = []

for file in filenames:
	# Lazily load in the data
    df = ____
    # Calculate the average danceability in the file of songs
    mean_danceability = ____
    danceabilities.append(mean_danceability)

# Compute all the mean danceabilities
danceability_list = ____
# Plot the results
____
plt.show()
Edit and Run Code