Advertisement
makispaiktis

Kaggle - Exercise 1 - Spotify: Times streamed for popular songs

Jul 1st, 2023
1,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import pandas as pd
  2. pd.plotting.register_matplotlib_converters()
  3. import matplotlib.pyplot as plt
  4. # %matplotlib inline
  5. import seaborn as sns
  6.  
  7.  
  8.  
  9. # 1. Read the file and show the first 5 and 5 last rows of the dataset
  10. spotify_filepath = "./spotify.csv"
  11. spotify_data = pd.read_csv(spotify_filepath, index_col="Date", parse_dates=True)
  12. print(spotify_data.head(), end='\n\n')
  13. print(spotify_data.tail(), end='\n\n')
  14.  
  15. # 2. Plot all the columns: horizontal axis is the date of the songs
  16. plt.figure(figsize=(14,6))
  17. plt.xlabel("Date")
  18. plt.ylabel("Times streamed")
  19. plt.title("Daily Global Streams of Popular Songs in 2017-2018")
  20. sns.lineplot(data=spotify_data)
  21. plt.show()
  22.  
  23. # 3. Plot 3 columns
  24. plt.figure(figsize=(14,6))
  25. plt.xlabel("Date")
  26. plt.ylabel("Times streamed")
  27. plt.title("Daily Global Streams of Popular Songs in 2017-2018")
  28. sns.lineplot(data=spotify_data['Shape of You'], label="Shape of You")
  29. sns.lineplot(data=spotify_data['Despacito'], label="Despacito")
  30. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement