我想创建一个基于多列pandas数据框的排名表,其中包含几个数字列。
让我们以下面的df为例:
<表类>
名称
销售
卷
评论
tbody><<tr>1000 100 100 B2000 200 50 C5400 500 10 表类>
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