2016-12-02 68 views
0

我有我的最后RDD,它看起来像:火花蟒蛇转换RDD元组的元组嵌套进事务所的元组

(44, (136.38, 2)) 
(2, (108.53, 3)) 
(4, (24.13, 1)) 
(35, (65.89, 1)) 

我想有它的形式:

(44, 136.38, 2) 
(2, 108.53, 3) 
(4, 24.13, 1) 
(35, 65.89, 1) 

请注意这是一个火花RDD,创造出另外两个RDDS的:

combined = reduced_total.join(reduced_count) 

我可以完成这个任务:

combined = combined.map(lambda x: (x[0],x[1][0],x[1][1])) 

但它似乎很Python的。任何更好的建议?

回答

2

可以解压:

combined.map(lambda x: (x[0], *x[1])) # Python 3 

或CONCAT:

# this creates a single element tuple and uses __add__ method on it. 
combined.map(lambda x: (x[0],) + x[1])