python - 使用 Spotipy API 循环遍历数据框和搜索轨道?
问题描述
我一直在编写一个 python 脚本来抓取 Billboard.com 并创建一个包含曲目标题和艺术家姓名的数据框。下面是相关的代码片段:
#compiles top 100 artist names/tracks
song_list = pd.DataFrame(
{
'tracks': tracks,
'artists': artists,
})
#search for each song and add as track id
track =
artist =
track_id = sp.search(q='artist:' + artist + ' track:' + track, type='track')
#create the playlist with the set variables/add tracks
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
playlists = sp.user_playlist_create(username, playlist_name,
description=playlist_description)
results = sp.user_playlist_add_tracks(username, playlist_id, track_ids)
print(results)
pprint.pprint(playlists)
else:
print("Can't get token for", username)
我试图从数据框中搜索每个艺术家姓名+曲目标题并将其添加到新创建的播放列表中。我知道我必须使用 for 循环,但我不确定如何将它与 spotipys 搜索功能结合使用。谢谢。
解决方案
推荐阅读
- c# - (Unity2D)如何让玩家根据精灵的颜色与平台进行交互?
- c++ - 使用 fstream 从 C++ 中的 .txt 文件获取文本的问题
- node.js - mongoose 无法找到 $geoNear 查询错误的索引
- coap - CoAP oneM2M 请求中的 filterCriter.attributes 是如何编码的?
- java - AWS DynamoDbException:提供的关键元素与架构不匹配
- json - 使用jq将json转换为csv文件?
- python - 我收到 HTTP 错误 403:检查 url 列表时出现禁止错误
- ubuntu - 虚拟盒子的主机名和端口号
- mongodb - 执行将我连接到 mongodb 数据库的函数时出现问题
- html - 为什么按钮不能正确浮动?