Home > Back-end >  I need only top 20 highest review count among all the cars bar graph?
I need only top 20 highest review count among all the cars bar graph?

Time:11-22

Basically i have a dataset with car models and i need a bar graph where the highest review count of 20 car brands should be displayed in the bar graph!

I have tried this below code but i am getting all the brand models from the dataset but i need only top 20 highest review count car brands in bar graph.

enter image description here

CodePudding user response:

import matplotlib.pyplot as plt

# sort the dataframe
df.sort_values(['reviews_count', 'car_name',], ascending=False, inplace=True)


plt.figure(figsize=(30,9))
x_zoom = np.linspace(-1, 1, 50)
y_zoom = np.sin(x_zoom)

plt.bar(df['car_name'][:20], df['reviews_count'][:20])

plt.xlabel("car name")
plt.ylabel("Review Count")
plt.xticks(rotation = 45)

plt.show()

enter image description here

  • Related