2017-04-07 74 views
0

我的数据帧是像下面 上校的名字指数,也就是说星火斯卡拉 - 如何为每个组创建新列,然后爆炸火花数据帧的列值

Index | words 
one | {col1: a, col2: b} 
one | {col1: c, col2: d} 
two | {col1: a, col2: b} 
two | {col1: e, col2: f} 

我期待输出像下面 输出DF列名一,二

one | two 
{col1: a, col2: b} | {col1: a, col2: b} 
{col1: c, col2: d} | {col1: e, col2: f} 

任何人都请帮我解决这个问题。我使用的火花1.5.2版本

回答

0

如果您确信每一个索引值,将有两个的话,你可以用下面的:

sqlContext.sql("select Index, collect_list(words)[0],collect_list(words)[1] from yourTable group by Index").show