1

hello everything is working fine but i gave custom range so now it is showing 10,9,8,7,6...1 , i want it from 1,2,3,4,5..10 , i am new to pandas so please help me out

data = pd.DataFrame(pd.read_csv("data.csv")
ConditionData = data.loc[:,['Country/Region','Confirmed']].sort_values(by="Confirmed",ascending=False).head(10)
ConditionData.index = range(10, 0, -1)
print(ConditionData)


    Country/Region  Confirmed
10              US    4290259
9           Brazil    2442375
8            India    1480073
7           Russia     816680
6     South Africa     452529
5           Mexico     395489
4             Peru     389717
3            Chile     347923
2   United Kingdom     301708
1             Iran     293606

somebody please help me

2 Answers 2

2

You can reset_index and add 1. This way you do not need to care about the number of rows:

ConditionData = ConditionData.reset_index(drop=True)
ConditionData.index += 1

NB. Indexing in python starts from 0, so unless you have a particular need for starting from 1, you might leave it as a zero based range

Sign up to request clarification or add additional context in comments.

Comments

0

Do you mean by...

ConditionData.index = range(1, 11)

Or reverse it with:

ConditionData.index = list(range(10, 0, -1))[::-1]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.