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
How can i get it sorted in a descending manner?
You can do it by changing your plotting line like this
df.letters.value_counts().sort_values().plot(kind = 'barh')
This might count as a bit of a hack, but try this:
df.letters.value_counts().sort_index(ascending=False).plot(kind='barh')