用熊猫排名的浮点数给了我错误的排名
我正在使用下面的代码创建一些资产的浮点数的排名,但是输出并未考虑小数点之前的两个数字,因此它首先将数字9.00、8.00、6.00放在数字17.00、16.00、15之前。 ,00。
df = df[['twelve_m_yield']]
df['ranking_twelve_m_yield'] = df['twelve_m_yield'].rank(ascending=False, method='first')
df = df.sort_values(by=['ranking_twelve_m_yield'])
print(df)
这就是结果:
twelve_m_yield ranking_twelve_m_yield
ticker
MGFF11 9.91 1.0
BTAL11 9.81 2.0
SARE11 9.75 3.0
KFOF11 9.54 4.0
...
KNRI11 6.88 20.0
HGPO11 6.72 21.0
HGBS11 6.56 22.0
VGHF11 17.01 23.0
VGIP11 15.87 24.0
DEVA11 15.73 25.0
...
IRDM11 12.95 36.0
CPTS11 12.95 37.0
TGAR11 12.06 38.0
HGCR11 11.76 39.0
OUFF11 11.68 40.0
````
But the result that I would like to achieve would be :
````
VGHF11 17.01 1.0
VGIP11 15.87 2.0
DEVA11 15.73 3.0
...
KNRI11 6.88 38.0
HGPO11 6.72 39.0
HGBS11 6.56 40.0
```
What should I change to achieve that? Thanks
I am creating a ranking of float numbers of some assets with the code below, but the output is not considering the two digits before the decimal point, so it is putting first the numbers 9.00, 8.00, 6.00 before the numbers 17.00, 16.00, 15,00.
df = df[['twelve_m_yield']]
df['ranking_twelve_m_yield'] = df['twelve_m_yield'].rank(ascending=False, method='first')
df = df.sort_values(by=['ranking_twelve_m_yield'])
print(df)
And that is the result:
twelve_m_yield ranking_twelve_m_yield
ticker
MGFF11 9.91 1.0
BTAL11 9.81 2.0
SARE11 9.75 3.0
KFOF11 9.54 4.0
...
KNRI11 6.88 20.0
HGPO11 6.72 21.0
HGBS11 6.56 22.0
VGHF11 17.01 23.0
VGIP11 15.87 24.0
DEVA11 15.73 25.0
...
IRDM11 12.95 36.0
CPTS11 12.95 37.0
TGAR11 12.06 38.0
HGCR11 11.76 39.0
OUFF11 11.68 40.0
````
But the result that I would like to achieve would be :
````
VGHF11 17.01 1.0
VGIP11 15.87 2.0
DEVA11 15.73 3.0
...
KNRI11 6.88 38.0
HGPO11 6.72 39.0
HGBS11 6.56 40.0
```
What should I change to achieve that? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中提到的那样,您的问题可能来自Twelve_m_yield列是对象类型。
结果:
As mentionned in comment your problem is probably coming from than the column twelve_m_yield is Object type.
Result: