简体   繁体   中英

Data sorting from Excel sheet

i tried to sort the values of particular row in data frame, the values are sorting but index values are not changing....i want to change the index values also according to the sorted data

rld=pd.read_excel(r"C:\Users\DELL\nagrajun sagar reservoir data - Copy.xlsx")
rl = rld.iloc[:,1].sort_values()
rl

output:

15    0.043
3     0.370
17    0.391
2     0.823
16    1.105
1     1.579
0     2.070
12    2.235
4     2.728
18    4.490
9     4.905
13    5.036
14    5.074
11    6.481
10    6.613
6     6.806
7     6.807
8     6.824
5     6.841
Name:  2  October, dtype: float64
rl[0]
output:
2.07

I expected rl[0] as 0.043 but actual result is 2.07 which is index value of before sorted list...

I suppose you can try reset_index() with (drop=True)

Something like rl=rl.reset_index(drop=True) in your case or you can do it while sorting like:

rl = rld.iloc[:,1].sort_values().reset_index(drop=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM