Spotipy:'Index out of range' 试图检索 album_ids 以便我可以获得它们的发布日期
Spotipy: 'Index out of range' when trying to retrieve album_ids so that I can get their release dates
我正在处理这些数据,它是我从 public 播放列表中提取的,并显示了自 1953 年以来的所有数字 1 及其音频特征:https://raw.githubusercontent.com/StanWaldron/StanWaldron.github.io/main/FinalData.csv
我现在正在尝试循环查找他们的专辑 ID,以便我可以检索他们的发行日期并根据其他时间序列数据绘制他们的音频特征,使用此代码:
def find_album_release(name):
album_ids = []
for x in name:
results = sp.search(q="album:" + x, type="album")
if not results["albums"]["items"]:
return []
album_id = results['albums']['items'][0]['uri']
album_ids.append(album_id)
print(album_id)
return album_ids
final = pd.read_csv('FinalData.csv')
albumlist = final['album']
finalalbums = find_album_release(albumlist)
前 7 个有效,然后 returns 无效。如果没有 if 语句,它 returns 索引超出范围。我已经通过在其专辑名称中进行硬编码来测试第 8 个元素,它 returns 是正确的结果,这与列表中的下 4 个元素相同,因此搜索这些专辑名称不是问题。我已经尝试过这些列表,但我不完全确定什么超出了范围。
非常感谢任何帮助
第 8 行专辑名称中包含单引号 (Don't Stop Me Eatin'
)。我试图删除引号并且它起作用了。也许您应该检查查询参数中允许使用哪些字符。
def find_album_release(name):
album_ids = []
for x in name:
x = x.replace("'", "") # Remove the quotes from album name
results = sp.search(q="album:" + x, type="album")
....
....
final = pd.read_csv('FinalData.csv')
albumlist = final['album']
finalalbums = find_album_release(albumlist)
我的输出:
spotify:album:31lHUoHC3P6BRFzKYLyRJO
spotify:album:6s84u2TUpR3wdUv4NgKA2j
spotify:album:4OyzQQJHEfKXRfyN4QyLR7
spotify:album:2Hjcfw8zHN4dJDZJGOzLd6
spotify:album:1zEBi4O4AaY5M55dUcUp3z
spotify:album:0Hi8bTOS35xZM0zZ6S89hT
spotify:album:5GGIgiGtxIgcVJQnsKQW94
spotify:album:3rLjiJI34bHFNIFqeK3y9s
spotify:album:6q1MiYTIE28nFzjkvLLt0I
spotify:album:61ulfFSmmxMhc2wCdmdMkN
spotify:album:3euz4vS7ezKGnNSwgyvKcd
spotify:album:1pFaEu56zqpzSviJc3htZN
spotify:album:4PTxbJPI4jj0Kx8hwr1v0T
spotify:album:2ogiazbrNEx0kQHGl5ZBTQ
spotify:album:5glfCPECXSHzidU6exW8wO
spotify:album:1XMw3pBrYeXzNXZXc84DNw
spotify:album:623PL2MBg50Br5dLXC9E9e
spotify:album:4TqgXMSSTwP3RCo3MMSR6t
spotify:album:3xIwVbGJuAcovYIhzbLO3J
spotify:album:3h2xv1tJgDnJZGy5Roxs5A
spotify:album:66xP0vUo8to8ALVpkyKc41
spotify:album:6XcYTEonLIpg9NpAbJnqrC
spotify:album:5sXSHscDjBez8VF20cSyad
spotify:album:6pQZPa398NswBXGYyqHH7y
spotify:album:0488X5veBK6t3vSmIiTDJY
我正在处理这些数据,它是我从 public 播放列表中提取的,并显示了自 1953 年以来的所有数字 1 及其音频特征:https://raw.githubusercontent.com/StanWaldron/StanWaldron.github.io/main/FinalData.csv
我现在正在尝试循环查找他们的专辑 ID,以便我可以检索他们的发行日期并根据其他时间序列数据绘制他们的音频特征,使用此代码:
def find_album_release(name):
album_ids = []
for x in name:
results = sp.search(q="album:" + x, type="album")
if not results["albums"]["items"]:
return []
album_id = results['albums']['items'][0]['uri']
album_ids.append(album_id)
print(album_id)
return album_ids
final = pd.read_csv('FinalData.csv')
albumlist = final['album']
finalalbums = find_album_release(albumlist)
前 7 个有效,然后 returns 无效。如果没有 if 语句,它 returns 索引超出范围。我已经通过在其专辑名称中进行硬编码来测试第 8 个元素,它 returns 是正确的结果,这与列表中的下 4 个元素相同,因此搜索这些专辑名称不是问题。我已经尝试过这些列表,但我不完全确定什么超出了范围。
非常感谢任何帮助
第 8 行专辑名称中包含单引号 (Don't Stop Me Eatin'
)。我试图删除引号并且它起作用了。也许您应该检查查询参数中允许使用哪些字符。
def find_album_release(name):
album_ids = []
for x in name:
x = x.replace("'", "") # Remove the quotes from album name
results = sp.search(q="album:" + x, type="album")
....
....
final = pd.read_csv('FinalData.csv')
albumlist = final['album']
finalalbums = find_album_release(albumlist)
我的输出:
spotify:album:31lHUoHC3P6BRFzKYLyRJO
spotify:album:6s84u2TUpR3wdUv4NgKA2j
spotify:album:4OyzQQJHEfKXRfyN4QyLR7
spotify:album:2Hjcfw8zHN4dJDZJGOzLd6
spotify:album:1zEBi4O4AaY5M55dUcUp3z
spotify:album:0Hi8bTOS35xZM0zZ6S89hT
spotify:album:5GGIgiGtxIgcVJQnsKQW94
spotify:album:3rLjiJI34bHFNIFqeK3y9s
spotify:album:6q1MiYTIE28nFzjkvLLt0I
spotify:album:61ulfFSmmxMhc2wCdmdMkN
spotify:album:3euz4vS7ezKGnNSwgyvKcd
spotify:album:1pFaEu56zqpzSviJc3htZN
spotify:album:4PTxbJPI4jj0Kx8hwr1v0T
spotify:album:2ogiazbrNEx0kQHGl5ZBTQ
spotify:album:5glfCPECXSHzidU6exW8wO
spotify:album:1XMw3pBrYeXzNXZXc84DNw
spotify:album:623PL2MBg50Br5dLXC9E9e
spotify:album:4TqgXMSSTwP3RCo3MMSR6t
spotify:album:3xIwVbGJuAcovYIhzbLO3J
spotify:album:3h2xv1tJgDnJZGy5Roxs5A
spotify:album:66xP0vUo8to8ALVpkyKc41
spotify:album:6XcYTEonLIpg9NpAbJnqrC
spotify:album:5sXSHscDjBez8VF20cSyad
spotify:album:6pQZPa398NswBXGYyqHH7y
spotify:album:0488X5veBK6t3vSmIiTDJY