简体   繁体   English

从Excel工作表进行数据排序

[英]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... 我期望rl[0]为0.043,但实际结果是2.07,这是排序列表之前的索引值...

I suppose you can try reset_index() with (drop=True) 我想你可以用(drop=True)尝试reset_index() (drop=True)

Something like rl=rl.reset_index(drop=True) in your case or you can do it while sorting like: 类似于rl=rl.reset_index(drop=True)的情况,或者您可以在排序时进行如下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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