简体   繁体   English

如何获取连续熊猫中具有最高值的列的名称

[英]How do I get the name of the column with the highest value in a row pandas

print(df_merged)

          VolumeOIH  VolumeKRE   SPY close  difference  
    0       300.0    51852.0     430.00       -6.67  
    1       700.0    54027.0     437.85        5.63  
    2       500.0    46517.0     435.72       -4.31  
    3      5100.0    43994.0     432.22        0.66  
    4     12400.0    52993.0     419.45      -10.84  
    ..        ...        ...        ...         ...  
    64     8677.0    11411.0     409.62       -5.06  
    65      911.0    17334.0     417.37        8.51  
    66     1990.0    16353.0     410.54       -2.34  
    67     1687.0    13611.0     411.77       -2.54  
    68     2307.0    11291.0     415.70        6.72  

As you can see my columns have different names.如您所见,我的列有不同的名称。 I want to create a new column that will simply show the name of the column with the highest volume.我想创建一个新列,它将简单地显示具有最高音量的列的名称。

If we take line 0, the highest volume is VolumeKRE.如果我们取第 0 行,则最高交易量是 VolumeKRE。 I want a new column to be created where the value on the first row would show : VolumeKRE.我想要创建一个新列,其中第一行的值将显示:VolumeKRE。

The following command will give you a column with the name of the maximum column:以下命令将为您提供一个具有最大列名称的列:

df_merged.idxmax(axis=1)

Then you can merge it to your original dataframe然后你可以将它合并到你的原始数据框

暂无
暂无

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

相关问题 如何获得熊猫中一个小组中最高价值的名称? - How do I get the name of the highest value in a group in Pandas? 如何向 pandas dataframe 添加一列,该列在一个范围内具有最高值但将其应用于每一行? - How do I add a column to a pandas dataframe which has the highest value in a range but applying it to every row? pandas:获取列和行名称,其中行对每一行具有最高值 - pandas: get column and row name where row has the highest value for every row 如何在 pandas dataframe 中依次获取最高、次高等数字的索引和列? - How do I sequentially get the index and column of the highest, next highest, etc. number in a pandas dataframe? 获取 Dataframe Pandas 中最大值的列和行索引 - Get Column and Row Index for Highest Value in Dataframe Pandas 如何获取pandas DataFrame中第二大行值的列名 - How to get column name for second largest row value in pandas DataFrame Python Pandas:保持列值最高的行 - Python pandas: keep row with highest column value 如何在csv文件中查找包含某行最高值的列名 - How to find column name that contains the highest value of a row in a csv file 如何从 pandas 中的列名中删除第二行? - How do I remove second row from the column name in pandas? Pandas 如何从一列创建重复列表,并且只保留对应列的最大值? - Pandas How do I create a list of duplicates from one column, and only keep the highest value for the corresponding columns?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM