Issue
So I have this code
w = Counter(df['col'].sum())
and to plot is by using
plt.bar(w.keys(), w.values())
how to limit to plot by top ten most valued from w? I tried to plot by using
w = Counter(twt['mentions'].sum()).most_common(10)
but it shown error: 'list' object has no attribute 'keys'
Solution
most_common()
returns a list of tuples (the most common k
items of the Counter). To transform that in a dict
so you can use it as per your line plt.bar...
, do:
w = dict(Counter(twt['mentions'].sum()).most_common(10))
Answered By - Pierre D
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.