Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

443
Views
pandas plot value counts barplot in descending manner

I have a dataframe where i am trying to count the occurrence of each value. I plot it as horizontal bar but cant get it to be sorted.

df = pd.DataFrame(['A','A','A','B','B','C'],columns = ['letters'])

df.value_counts()

A 3
B 2
C 1

enter image description here

How can i get it sorted in a descending manner?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can do it by changing your plotting line like this

df.letters.value_counts().sort_values().plot(kind = 'barh')
over 4 years ago · Santiago Trujillo Report

0

This might count as a bit of a hack, but try this:

df.letters.value_counts().sort_index(ascending=False).plot(kind='barh')
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!