filter(func):
1、选出所有func返回值为true的元素,生成一个新的分布式数据集返回
如图:
示例代码:
实现 Rdd ,每个元素*2,并输出结果>5的数据
def my_filter(): data = [1,2,3,4,5] rdd1 =sc.parallelize(data) map_rdd = rdd1.map(lambda x:x*2)
print(map_rdd.collect()) filter_rdd = map_rdd.filter(lambda x:x>5)
print(filter_rdd.collect())
#链示实示方式
#sc.parallelize(data).map(lambda x:x*2).filter(lambda x:x>5).collect()