2016-12-02 64 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])