我有這樣的列一個數據幀:列出熊貓集團最常見的會員?
id lead_sponsor lead_sponsor_class
02837692 Janssen Research & Development, LLC Industry
02837679 Aarhus University Hospital Other
02837666 Universidad Autonoma de Ciudad Juarez Other
02837653 Universidad Autonoma de Madrid Other
02837640 Beirut Eye Specialist Hospital Other
我想找到最常見的主要發起者。我可以列出使用每個組的大小:
df.groupby(['lead_sponsor', 'lead_sponsor_class']).size()
,給了我這樣的:
lead_sponsor lead_sponsor_class
307 Hospital of PLA Other 1
3E Therapeutics Corporation Industry 1
3M Industry 4
4SC AG Industry 8
5 Santé Other 1
但我怎麼找到頂級的10種最常見的羣體?如果我做的:
df.groupby(['lead_sponsor', 'lead_sponsor_class']).size().sort_values(ascending=False).head(10)
然後我得到一個錯誤:
AttributeError: 'Series' object has no attribute 'sort_values'
對我而言,您的解決方案也適用。 – jezrael