Python等级:给负数负数
我有一组基本的数据集:
ID Value
A 0.1
B 0.2
C -0.1
D -0.01
E 0.15
如果我们使用data.rank(),我们会得到结果:
ID Value
A 3
B 5
C 1
D 2
E 4
但是我想拥有的,以使负值导致负等级,例如:
ID Value
A 1
B 3
C -2
D -1
E 2
基本等级给出负值一个负等级虽然后期值获得了正等级,但我们获得了1到5,我们得到1到3和-1至-2。 任何帮助都大大关注。
I have a basic set of data like:
ID Value
A 0.1
B 0.2
C -0.1
D -0.01
E 0.15
If we use data.rank() we get the result:
ID Value
A 3
B 5
C 1
D 2
E 4
But i want to have so that the negative values result in an negative rank instead such as:
ID Value
A 1
B 3
C -2
D -1
E 2
Basically rank give the negative values an negative rank while the postive values get a positive rank but instead of 1 to 5 we get 1 to 3 and -1 to -2.
Any help is greatly apreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种类似于Concat答案的方法,但不是像Compact:
输出:
编辑:我注意到负等级未遵循您在帖子中指定的顺序,因此我在Rank()中添加了“ Aspending = false”以解决这一点。
Another method similar to the concat answer, but not as compact:
Output:
Edit: I noticed that the negative rank did not follow the order you specified in your post, so I added "ascending=False" in rank() to address that.
分别对您的正值和负值排名,然后
concat
它们:Rank your positive values and negative values separately and then
concat
them:在框外思考&对您的值进行排序。
Think outside the box & sort your values.