Skip to content
Advertisement

How do I display the top & bottom 5 row values along with custom row values in Matplotlib?

I have a dataframe that’s about 750 odd rows, which is obviously excessive for a traditional bar chart. What I would like to do is have it display the Top 5 entries, the specific criteria that I’m looking for, and the bottom 5 entries.

The dataframe is something like this:

JavaScript

What I want to be able to do is display the bar graph so it selects the Top 5 (where 1 is highest) entries (Dog, Pig, Chicken, Cat, Fox) and then a specific entry in the list (the beetle) and then the bottom 5 entries (Tiger, Lion, Zebra, Gorilla, Seahorse) and the corresponding ‘score’ for those entries.

Is this even possible?

Thanks in advance for your help!

Update: The original answer gave me additional entries on the right-side of the graph, no matter how many times I modified the concat field. Perhaps due to the 750 entries in my df? Answer: NaN values were giving me blank values, which is the reason. These have been taken into account by me.

Advertisement

Answer

JavaScript

enter image description here

Advertisement