我如何获得排名前5的电影制片厂(分配给b)并将其显示在条形图上? [关闭]

问题描述 投票:-6回答:1
import pandas as pd  
import numpy as np
import matplotlib.pyplot as plt 

movies = pd.read_csv('https://myshare.leuphana.de/?t=575bdba72855fc993cd6a6e842bcde29')

b = ('Independent', 'Disney', 'Fox', 'Warner Bros.', 'Summit')
c = (3,19,8,6,2,14,5,4,2,1,4,1)

a = {"Leadstudio":["The Weistein Company", "Independent", "Disney", "Fox", 
    "20th Century Fox", "Warner Bros.", "Summit", "Paramount","Lionsgate","New Line","Sony","CBS"],
     "Occurrences":[3,19,8,6,2,14,5,4,2,1,4,1]}

y = pd.DataFrame(a)
print(y)


#b Top 5 Leadstudios

import matplotlib.pyplot as plt

plt.bar(b,c)
plt.xlabel("Movies")
plt.ylabel("Occurrences")
plt.show()

所以这就是我的工作方式,我认为问题出在plt.bar()中,所以请向我展示我在这里所缺少的。

python pandas numpy dataframe matplotlib
1个回答
0
投票
IIUC,

y.set_index('Leadstudio').sort_values('Occurrences',ascending=False).head(5).plot(kind='bar')

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.