如何为给定的具有多个数字列的pandas数据框创建排名表?



我想创建一个基于多列pandas数据框的排名表,其中包含几个数字列。

让我们以下面的df为例:

<表类> 名称 销售 卷 评论 tbody><<tr>1000100100B200020050C540050010
df.set_index('Name').rank().reset_index()
Name    Sales   Volume  Reviews
0   A       1.0     1.0     1.0
1   B       2.0     2.0     2.0
2   C       3.0     3.0     3.0

你可以使用transform/apply来点击每一列

df.set_index('Name').transform(pd.Series.rank, ascending = False)
Sales  Volume  Reviews
Name
A       3.0     3.0      1.0
B       2.0     2.0      2.0
C       1.0     1.0      3.0

最新更新