1 Star 17 Fork 16

NovemberRain/pyspark_project

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
spark0403.py 588 Bytes
一键复制 编辑 原始数据 按行查看 历史
迪卡普里奥 提交于 2019-11-03 13:27 +08:00 . pyspark
import sys
from pyspark import SparkConf, SparkContext
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: topn <input>", file=sys.stderr)
sys.exit(-1)
conf = SparkConf()
sc = SparkContext(conf=conf)
counts = sc.textFile(sys.argv[1])\
.map(lambda x:x.split("\t"))\
.map(lambda x:(x[5],1))\
.reduceByKey(lambda a,b:a+b)\
.map(lambda x:(x[1],x[0]))\
.sortByKey(False)\
.map(lambda x:(x[1],x[0])).take(5)
for (word, count) in counts:
print("%s: %i" % (word, count))
sc.stop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cucy/pyspark_project.git
git@gitee.com:cucy/pyspark_project.git
cucy
pyspark_project
pyspark_project
master

搜索帮助