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. 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
pd.Series(l).explode().dropna().\
value_counts(normalize=True).sort_values(ascending=False).head(10).plot(kind='bar')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.