简体   繁体   English

y 轴上的百分比

[英]Percentage on y-axis

Using this list of lists as a dataset:将此列表列表用作数据集:

my list= [[],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     ['EMF'],
     ['body'],
     [],
     [],
     [],
     [],
     ['water', 'juice'],
     ['What', 'are', 'u', 'doing'],
     [],
     [],
     [],
     [],
     [],
     [],
     [],
     ['EVENT'],
     ['christmas'],
     [],
     ['shalala'],
     ['happy'],
     []]

I would like to plot the percentage on the y-axis of this data compared to the total.我想 plot 这个数据在 y 轴上与总数相比的百分比。 I have tried with this:我试过这个:

cnt = Counter(chain.from_iterable(df)) # df is the dataframe generated from the list above
plt.bar(*zip(*cnt.most_common(20)))
plt.xticks(rotation=60)
plt.show()

The problem is that I do not know how to the the percentage.问题是我不知道百分比如何。 I hope you can help.我希望你能帮忙。

Let us try value_counts让我们试试value_counts

pd.Series(l).explode().dropna().\
      value_counts(normalize=True).sort_values(ascending=False).head(10).plot(kind='bar')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM