我有一个DataFrame:
name column1 column2 column3 column4
first 2 1 2.1 5.4
test 1.5 0.5 0.9 3.7
choose 7 2.9 9.1 2.5
我想要一个带有包含列的新数据框,列名称包含row的最大值:
| name | max_column |
|--------|------------|
| first | column4 |
| test | column4 |
| choose | column3 |
非常感谢您的支持 .
3 回答
可能有一些更好的编写UDF的方法 . 但这可能是有效的解决方案
Output
完成工作后,绕道RDD并使用'getValuesMap' .
简单的解决方案是
但是如果你想从原始数据框中取回所有列(比如Scala/Spark dataframes: find the column name corresponding to the max),你必须在合并行和扩展模式时玩一点
我想发布我的最终解决方案:
它工作得非常快 .