ERJAN
ERJAN

Reputation: 24500

How to sort by index values then plot pandas dataframe?

I'm plotting this dataframe of 1-5 stars and it works fine.

5 4424

4 2177

1 1529

3 1070

2 800

However, i want to sort the indices in ascending order - "1,2,3,4,5", not plot it by the actual values: kk

the code that plots:

j.sort_index(by='stars').plot(kind='bar', rot = 1, figsize=(15,6))

I want the indexes to come in ascending order - 1,2,3,4,5.

Upvotes: 1

Views: 1315

Answers (1)

jezrael
jezrael

Reputation: 862771

Remove parameter by from sort_index for sorting by default index values:

j.sort_index().plot(kind='bar', rot = 1, figsize=(15,6))

Upvotes: 2

Related Questions