>>> rdd = sc.parallelize([("a", ""), ("b", 1), ("a", 1), ("a", 1)])
>>> rdd.distinct().countByKey().items()
[('a', 2), ('b', 1)] OR: from operator import add
rdd.distinct().map(lambda x: (x[0], 1)).reduceByKey(add)
rdd.distinct().keys().map(lambda x: (x, 1)).reduceByKey(add)

distinct(numPartitions=None)

Return a new RDD containing the distinct elements in this RDD.

>>> sorted(sc.parallelize([1, 1, 2, 3]).distinct().collect())
[1, 2, 3]

countByKey()

Count the number of elements for each key, and return the result to the master as a dictionary.

>>> rdd = sc.parallelize([("a", 1), ("b", 1), ("a", 1)])
>>> sorted(rdd.countByKey().items())
[('a', 2), ('b', 1)]

最新文章

  1. Take into Action!
  2. Selenium-java-testng插件安装eclipse
  3. DIB位图(Bitmap)的读取和保存
  4. iOS离屏渲染简书
  5. js做计算器
  6. GetStoredProcCommand和GetSqlStringCommand的区别
  7. git 放弃本地修改 强制更新
  8. 清空select内容
  9. java web 之 web.xml篇
  10. 高质量代码之HTML、CSS篇
  11. iOS开发——实用篇&提高iOS开发效率的方法和工具
  12. python百科
  13. JS 新浪API获取IP归属地
  14. 团队开发冲刺2-----2day
  15. postgresql 导出函数的方法
  16. @media 针对不同的屏幕尺寸设置不同的样式
  17. jquery的attr()方法
  18. C#Enum用Tuple保存值绑定到前端的CheckBox
  19. js中事件绑定要注意的事项之如何在方法中自己打印自己的值
  20. suricata 原文记录

热门文章

  1. JQuery 动态创建表单,并自动提交
  2. 《java数据结构与算法》系列之“快速排序"
  3. OpenCV: OpenCV人脸检测框可信度排序
  4. VS2013配置编译Caffe-Win10_X64
  5. ANE打包
  6. MySQL在Linux下的表名如何不区分大小写
  7. 死磕itchat源码--config.py
  8. Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法
  9. 谨慎调整内核参数:vm.min_free_kbytes
  10. HTTP 状态码之:301、302 重定向