【发布时间】:2019-08-07 09:05:10
【问题描述】:
我在 spark.dataframe A 中有类似的数据:
Ben 1
Ben 2
Ben 4
Ben 3
Jerry 2
Jerry 2
Jane 3
Jane 5
James 1
James 1
我们的 Action_id 范围是 1-5。 我们想像这样得到 spark.dataframe B:
Name Action_id=1 Action_id=2 Action_id=3 Action_id=4 Action_id=5
Ben 1 1 1 1 0
Jane 0 0 1 0 1
Jerry 0 2 0 0 0
James 2 0 0 0 0
例如,(Ben,Action_id=1) 中的 '1' 表示在前一个数据帧中,Ben 执行了一次动作 1。
如何将数据帧 A 转换为数据帧 B?
【问题讨论】: