Reputation: 1711
I have a huge dataset with hundreds of cities. I want to make a bar chart with just the 50 most occurring cities.
Here is what I have so far:
base_color = sb.color_palette()[0]
cat_order = planes_df['OriginCityName'].value_counts().index
plt.figure(figsize = [11, 5])
sb.countplot(data = planes_df, x = 'OriginCityName', color = base_color, order = cat_order)
plt.title('# of planes that takeoff from the origin state')
plt.xlabel('Origin States')
plt.ylabel('Number of Planes')
plt.xticks(rotation = 90);
This plots hundreds of cities. How can I just plot the 50 most frequest cities?
I know there must be a limiter....
Upvotes: 1
Views: 99
Reputation: 5741
You could take the .head()
after sorting using .sort_values()
and assign that to cat_order
:
planes_df['OriginCityName'].value_counts().sort_values().head(50).index
Upvotes: 1