spark groupByKey 也是可以filter的
2024-08-27 01:30:45
>>> v=sc.parallelize(["one", "two", "two", "three", "three", "three"])
>>> v2=v.map(lambda x: (x,1))
>>> v2.collect()
[('one', 1), ('two', 1), ('two', 1), ('three', 1), ('three', 1), ('three', 1)]
>>> v3=v2.groupByKey()
>>> v3.collect()
[('one', <pyspark.resultiterable.ResultIterable object at 0x7fd3c7850e90>), ('two', <pyspark.resultiterable.ResultIterable object at 0x7fd3c7850f10>), ('three', <pyspark.resultiterable.ResultIterable object at 0x7fd3c6dc83d0>)]
>>> v4=v3.filter(lambda x:len(x[1].data)>2)
>>> v4.collect()
[('three', <pyspark.resultiterable.ResultIterable object at 0x7fd3c6dc8510>)]
过滤了出现次数大于2的结果。
最新文章
- VVDocumenter 注释工具的使用
- 【leetcode❤python】 112. Path Sum
- spring mvc 异常统一处理方式
- 【转】JavaScript系列文章:自动类型转换
- Java中char占用几个字节
- salesforce 零基础学习(六十八)http callout test class写法
- javascript 函数和作用域(函数,this)(六)
- 与redmine对接
- 【并查集】HDU 1325 Is It A Tree?
- POJ2503-Babelfish-二分
- PTA4
- 7、...arg ...[1,2,3] 数组扩展
- ELK收集tomcat访问日志并存取mysql数据库案例
- CSS3之box-sizing属性
- window下配置SSH连接GitHub、GitHub配置ssh key
- Linux基础知识之用户和用户组以及 Linux 权限管理
- $使用dom4j可解析 返回&;#x等字样的 html转义字符【转】
- 关于Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题的解决方案
- hung task机制
- centos7修改默认运行级别的变化