Act fast, special offers end soon! Up to $294 is savings when you get Premium today.
Get offer codes

Summarising small slices of pie chart into Others slice

Lets say we’re working on ebay cars data, and we want to plot a pie chart based on each brands share of that database:

autos["brand"].value_counts().plot.pie()
plt.ylabel("")
plt.show()

badpie

Doesn’t look nice hey?
Solution:

pie_frame = pd.DataFrame()
pie_frame['brand'] = autos["brand"]
others = pie_frame['brand'].value_counts()[10:].index
pie_frame.loc[pie_frame['brand'].isin(others),'brand'] = 'other'
pie_frame["brand"].value_counts().plot.pie()
plt.ylabel("")
plt.show()

goodpie

Later we can change the sequence of slices and sort out the colors, but…
is this the best/ easiest solution? Does matplotlib have anything built in for this issue?