08 分布式计算MapReduce--词频统计
def getText():
txt=open("D:\\test.txt","r").read()
txt=txt.lower()
punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~“”?,!【】()、。:;’‘……¥·"""
for ch in punctuation:
txt=txt.replace(ch,"")
return txt
hamletTxt=getText()
words=hamletTxt.split()
counts={}
for word in words:
counts[word]=counts.get(word,0)+1
items=list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(100):
word,count=items[i]
print("{0:<10}{1:>5}".format(word,count))
#!/usr/bin/env python
import sys
for line in sys.stdin:
line = line.strip()
words=line.split()
for word in words:
print("{}\t{}".format(word,1))
#!/usr/bin/env python
from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
for line in sys.stdin:
line = line.strip()
word, count = line.split('\t', 1)
try:
count = int(count)
except ValueError:
continue
if current_word == word:
current_count += count
else:
if current_word:
print "%s\t%s" % (current_word, current_count)
current_count = count
current_word = word
if word == current_word:
print "%s\t%s" % (current_word, current_count)
2.3分布式运行自带词频统计示例
- 启动HDFS与YARN
- 准备待处理文件
- 上传HDFS
- 运行hadoop-mapreduce-examples-2.7.1.jar
- 查看结果

2.4 分布式运行自写的词频统计
- 停止HDFS与YARN

08 分布式计算MapReduce--词频统计的更多相关文章
- MapReduce词频统计
自定义Mapper实现 import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; impor ...
- MapReduce实现词频统计
问题描述:现在有n个文本文件,使用MapReduce的方法实现词频统计. 附上统计词频的关键代码,首先是一个通用的MapReduce模块: class MapReduce: __doc__ = ''' ...
- Hadoop之词频统计小实验
声明: 1)本文由我原创撰写,转载时请注明出处,侵权必究. 2)本小实验工作环境为Ubuntu操作系统,hadoop1-2-1,jdk1.8.0. 3)统计词频工作在单节点的伪分布上,至于真正实 ...
- Hadoop上的中文分词与词频统计实践 (有待学习 http://www.cnblogs.com/jiejue/archive/2012/12/16/2820788.html)
解决问题的方案 Hadoop上的中文分词与词频统计实践 首先来推荐相关材料:http://xiaoxia.org/2011/12/18/map-reduce-program-of-rmm-word-c ...
- 【原创】大数据基础之词频统计Word Count
对文件进行词频统计,是一个大数据领域的hello word级别的应用,来看下实现有多简单: 1 Linux单机处理 egrep -o "\b[[:alpha:]]+\b" test ...
- Hive简单编程实践-词频统计
一.使用MapReduce的方式进行词频统计 (1)在HDFS用户目录下创建input文件夹 hdfs dfs -mkdir input 注意:林子雨老师的博客(http://dblab.xmu.ed ...
- hive进行词频统计
统计文件信息: $ /opt/cdh-5.3.6/hadoop-2.5.0/bin/hdfs dfs -text /user/hadoop/wordcount/input/wc.input hadoo ...
- Hadoop的改进实验(中文分词词频统计及英文词频统计)(4/4)
声明: 1)本文由我bitpeach原创撰写,转载时请注明出处,侵权必究. 2)本小实验工作环境为Windows系统下的百度云(联网),和Ubuntu系统的hadoop1-2-1(自己提前配好).如不 ...
- 初学Hadoop之中文词频统计
1.安装eclipse 准备 eclipse-dsl-luna-SR2-linux-gtk-x86_64.tar.gz 安装 1.解压文件. 2.创建图标. ln -s /opt/eclipse/ec ...
- 初学Hadoop之WordCount词频统计
1.WordCount源码 将源码文件WordCount.java放到Hadoop2.6.0文件夹中. import java.io.IOException; import java.util.Str ...
随机推荐
- insert image in mail instead of attachment
https://www.extendoffice.com/documents/outlook/3810-outlook-insert-images-inline.html Go ahead to cl ...
- 一、mysql基础
说明:学习视频参考尚硅谷--康师傅 第一章.数据库概述 1.为什么使用数据库?why? 持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用.大多数情况下,特别是企业级应用,数 ...
- DOS下的一些命令
DOS一些命令 1.查看无线密码 netsh wlan show profiles #显示所有本地电脑加入过的wlan netsh wlan show profiles name=&q ...
- Kubernetes学习笔记(二)
[查看pod里container的logs] kubectl logs nginx --all-containers=true #Return snapshot lo ...
- wake on lan magic packet
局域网模式,必须电脑和手机在同一个 局域网,或者是网段内 外网模式 这个就是,你拿着手机,在任何地方,都可以开机电脑.
- 统计 nginx access.log
awk '{print $1}' access22.log | sort | uniq -c | sort -nr -k1
- 代码行数统计(指定目录下所有文件的Line)
遍历文件夹计算文件行数(Windows) 主要使用的是 FindFirstFile. FindNextFile函数寻找子目录下的文件,使用 WIN32_FIND_DATA(文件属性) 结构体 #def ...
- jubyter notebook 安装conda 虚拟环境
- 打包exe
2.要打包的文件为多个py文件 这种情况一般你的代码较多,项目较大,可能你写了一个GUI界面py文件这个文件调用了其他文件的函数什么的,这个时候你需要生成spec文件来打包,这里假设你的要打包的主文件 ...
- PHP表单验证内容是否为空的实现代码
<!doctype html> <html> <head> <meta http-equiv="conent-type" conten ...


