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'
CodePudding user response:
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))
