- PySpark Cookbook
- Denny Lee Tomasz Drabas
- 91字
- 2021-06-18 19:06:38
.flatMap(...) transformation
The flatMap(f) transformation is similar to map, but the new RDD flattens out all of the elements (that is, a sequence of events). Let's look at the following snippet:
# Filter only second column == "WA",
# select first two columns within the RDD,
# and flatten out all values
(
airports
.filter(lambda c: c[1] == "WA")
.map(lambda c: (c[0], c[1]))
.flatMap(lambda x: x)
.take(10)
)
The preceding code will produce the following output:
# Output
[u'Bellingham',
u'WA',
u'Moses Lake',
u'WA',
u'Pasco',
u'WA',
u'Pullman',
u'WA',
u'Seattle',
u'WA']
推薦閱讀
- JSP網絡編程(學習筆記)
- Visual C++程序設計學習筆記
- Beginning C++ Game Programming
- Python for Secret Agents:Volume II
- Elastic Stack應用寶典
- OpenStack Orchestration
- Learning AWS
- PHP與MySQL權威指南
- Python網絡爬蟲實例教程(視頻講解版)
- Groovy 2 Cookbook
- DevOps 精要:業務視角
- Java EE 7 Development with WildFly
- Learn C Programming
- ServiceDesk Plus 8.x Essentials
- GitHub Essentials