Python Forum
Using Pandas to store spotipy output in csv (python)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Pandas to store spotipy output in csv (python)
#1
Hi everyone,

I want to use spotipy to collect data from the spotify API.
I was able to make it work with:


import pandas as pd
import spotipy
sp = spotipy.Spotify()

from spotipy.oauth2 import SpotifyClientCredentials 

cid ='XXXCIDXXX' 
secret = 'XXXSECRETXXX' 
client_credentials_manager = SpotifyClientCredentials(client_id=cid, 
client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) 
sp.trace=False 

playlist = sp.user_playlist_tracks('spotify', '37i9dQZF1DX5nwnRMcdReF') 
songs = playlist['items']

df = pd.DataFrame(songs)

df.to_csv('Songs.csv', sep=';', encoding='utf-8', index=True)
This Outputs a a lot of data that i dont Need.
I found a code to only output the data that I need which is:

for i, item in enumerate(playlist['items']):
    track = item['track']
    need = (i, track['artists'][0]['name'], track['name'], track['id'])
now i can use print(need) to output exactly what I want, but I dont know how to store the data into the DataFrame.

If someone could help me that would be great.

Thank you.
Reply


Messages In This Thread
Using Pandas to store spotipy output in csv (python) - by pouyonsel - Jan-23-2018, 09:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add NER output to pandas dataframe dg3000 0 282 Apr-22-2024, 08:14 PM
Last Post: dg3000
  No Output In Pandas DataFrame Query eddywinch82 1 1,966 Aug-17-2020, 09:25 PM
Last Post: eddywinch82
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 2,264 Mar-28-2020, 08:27 AM
Last Post: j.crater
  Can't store pandas converted json dataframe into mongoDB mahmoud899 1 4,297 Dec-12-2018, 07:45 PM
Last Post: nilamo
  Output substrings from rows in pandas brocq_18 5 4,067 Jun-21-2018, 11:30 AM
Last Post: brocq_18
  Issue in getting the required data from nested json and store it in a pandas datafram PrateekG 2 3,355 May-20-2018, 11:25 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020