【问题标题】:Pivot aggregation filling columns with value on the same row in PySpark在 PySpark 的同一行上用值透视聚合填充列
【发布时间】:2022-12-10 11:41:23
【问题描述】:

我需要用答案填充列的数据透视聚合。

下面是例子,谢谢!

Input

id question answer
1 quest_1 Good
1 quest_2 Bad
2 quest_1 Bad
2 quest_2 Good
2 quest_3 Quite Good

Output

id quest_1 quest_2 quest_3
1 Good Bad NULL
2 Bad Good Quite Good

【问题讨论】:

    标签: pyspark group-by apache-spark-sql pivot transpose


    【解决方案1】:

    做一个支点

     df.groupby('id').pivot('question').agg(first('answer')).show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 2017-10-29
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      相关资源
      最近更新 更多