I have the following pandas dataframe
+---------+-------+
| Country | value |
+---------+-------+
| UK | 42 |
| US | 9 |
| US | 10 |
| France | 15 |
| France | 16 |
| Germany | 17 |
| Germany | 18 |
| Germany | 20 |
+---------+-------+
我想创建一个新的列,根据每个国家的值的平均值从大到小进行排名。
输出结果如下:
+---------+-------+---------+------+
| Country | value | Average | Rank |
+---------+-------+---------+------+
| UK | 42 | 42 | 1 |
| US | 9 | 9.5 | 4 |
| US | 10 | 9.5 | 4 |
| France | 15 | 15.5 | 3 |
| France | 16 | 15.5 | 3 |
| Germany | 17 | 18 | 2 |
| Germany | 18 | 18 | 2 |
| Germany | 20 | 18 | 2 |
+---------+-------+---------+------+
请注意,我不需要平均值列,它只是为了说明而存在。
非常感谢。