简体   繁体   English

如何根据 Pandas 中其他列的增加值添加新列排名

[英]How to add a new column rank on based on increasing value of other column in Pandas

I have this dataframe with which i am trying to create a new column rank on basis of increasing values of column Opportunity with pandas我有这个 dataframe,我正在尝试根据 pandas 列Opportunity的增加值创建一个新的列排名

State   Brand       DYA     Opportunity
Delhi   Pampers     -8.58   -1.24139
Delhi   Ariel       0.53    0.04800
Delhi   Fusion      0.68    0.00492
Delhi   Gillette    1.56    0.02073

required output --必填 output --

State   Brand       DYA     Opportunity Rank
Delhi   Pampers     -8.58   -1.24139     1
Delhi   Ariel       0.53    0.04800      4      
Delhi   Fusion      0.68    0.00492      2
Delhi   Gillette    1.56    0.02073      3

You can use rank function:您可以使用rank function:

df['Rank'] = df['Opportunity'].rank()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据不同条件在其他列上添加新列 pandas - How to add a new column based on different conditions on other columns pandas 如何在 Pandas 中创建一个新列并根据现有列中的条件值向该新列添加值? - How to create a new column in pandas and add value to that new column based on the conditional value from the existing column? Pandas - 添加一个新列,根据其他列值从 arrays 中提取值 - Pandas - Add a new column extracting value from arrays based on other column value pandas 为每列添加新的“排名”列 - pandas Add new "rank" columns for every column pandas 根据条件将值添加到新列 - pandas add value to new column based on condition 根据列的总和添加新列,并在Pandas中按2个其他列分组 - Add new column based on sum of a column and grouped by 2 other columns in Pandas Pandas - 根据列值对输入值进行排名 - Pandas - rank the input value based on column values 如何根据其他 pandas 列和关联的字符串列的最大值创建新的 pandas 列? - How can I create a new pandas column based on the max value of other pandas columns and the associated string column? MemoryError pandas根据其他列值生成新列 - MemoryError pandas generate new column based on other column value Pandas 根据其他列中的条件和值创建新列 - Pandas Create New Column Based Off of Condition and Value in Other Column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM