相关疑难解决方法(0)

找到每行具有最大值的列名称

我有一个像这样的DataFrame:

In [7]:
frame.head()
Out[7]:
Communications and Search   Business    General Lifestyle
0   0.745763    0.050847    0.118644    0.084746
0   0.333333    0.000000    0.583333    0.083333
0   0.617021    0.042553    0.297872    0.042553
0   0.435897    0.000000    0.410256    0.153846
0   0.358974    0.076923    0.410256    0.153846
Run Code Online (Sandbox Code Playgroud)

在这里,我想询问如何获取每行具有最大值的列名,所需的输出如下:

In [7]:
    frame.head()
    Out[7]:
    Communications and Search   Business    General Lifestyle   Max
    0   0.745763    0.050847    0.118644    0.084746           Communications 
    0   0.333333    0.000000    0.583333    0.083333           Business  
    0   0.617021    0.042553    0.297872    0.042553           Communications 
    0   0.435897    0.000000    0.410256    0.153846           Communications 
    0   0.358974    0.076923    0.410256    0.153846           Business 
Run Code Online (Sandbox Code Playgroud)

python max dataframe pandas

97
推荐指数
4
解决办法
5万
查看次数

对于每一行,返回最大值的列名

我有一个员工名单,我需要知道他们最常在哪个部门.将员工ID与部门名称制表是微不足道的,但从频率表中返回部门名称而不是名册数量是很棘手的.下面是一个简单示例(列名=部门,行名=员工ID).

DF <- matrix(sample(1:9,9),ncol=3,nrow=3)
DF <- as.data.frame.matrix(DF)
> DF
  V1 V2 V3
1  2  7  9
2  8  3  6
3  1  5  4
Run Code Online (Sandbox Code Playgroud)

现在我该怎么办?

> DF2
  RE
1 V3
2 V1
3 V2
Run Code Online (Sandbox Code Playgroud)

r

76
推荐指数
6
解决办法
7万
查看次数

标签 统计

dataframe ×1

max ×1

pandas ×1

python ×1

r ×1