我想在数据集上创建一张柱状图,显示所有时间排名前500首歌曲中拥有最多歌曲的前10位艺术家。我已经得到了结果,但是我不知道该如何将其可视化。我需要用代码生成一个柱状图来展示我得到的输出结果。 我已经导入了pandas、seaborn和matplot,只需要帮助我编写代码。
counts = dict()
for artists in my_data['artist']:
counts[artists] = counts.get(artists, 0) + 1
def keyfunction(k):
return counts[k]
plt.figure(figsize = (10, 30))
plt.title("Greatest Artists of All Time")
data = dict()
for key in sorted(counts, key=keyfunction, reverse=True)[:10]:
print(key, counts[key])
需要制作以下输出的条形图。
Elton John 18
The Beatles 16
Elvis Presley 12
The Jimi Hendrix Experience 12
The Four Tops 10
Muddy Waters 8
Sam Cooke 8
The Clash 8
U2 8
The Isley Brothers 8