- PySpark Cookbook
- Denny Lee Tomasz Drabas
- 134字
- 2021-06-18 19:06:39
.union(...) transformation
The union(RDD) transformation returns a new RDD that is the union of the source and argument RDDs. Look at the following code snippet:
# Create `a` RDD of Washington airports
a = (
airports
.zipWithIndex()
.filter(lambda (row, idx): idx > 0)
.map(lambda (row, idx): row)
.filter(lambda c: c[1] == "WA")
)
# Create `b` RDD of British Columbia airports
b = (
airports
.zipWithIndex()
.filter(lambda (row, idx): idx > 0)
.map(lambda (row, idx): row)
.filter(lambda c: c[1] == "BC")
)
# Union WA and BC airports
a.union(b).collect()
This will generate the following output:
# Output
[[u'Bellingham', u'WA', u'USA', u'BLI'],
[u'Moses Lake', u'WA', u'USA', u'MWH'],
[u'Pasco', u'WA', u'USA', u'PSC'],
[u'Pullman', u'WA', u'USA', u'PUW'],
[u'Seattle', u'WA', u'USA', u'SEA'],
...
[u'Vancouver', u'BC', u'Canada', u'YVR'],
[u'Victoria', u'BC', u'Canada', u'YYJ'],
[u'Williams Lake', u'BC', u'Canada', u'YWL']]
推薦閱讀
- 國際大學生程序設計競賽中山大學內部選拔真題解(二)
- C語言程序設計(第3版)
- The Android Game Developer's Handbook
- 騰訊iOS測試實踐
- Pandas Cookbook
- Python從小白到大牛
- Unity 2020 Mobile Game Development
- Python Tools for Visual Studio
- ServiceNow:Building Powerful Workflows
- 區塊鏈技術進階與實戰(第2版)
- Mastering Web Application Development with AngularJS
- 小型編譯器設計實踐
- C++ Application Development with Code:Blocks
- 深度探索Go語言:對象模型與runtime的原理特性及應用
- Clojure編程樂趣