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 ...
随机推荐
- js 评论时间换算
//时间戳换算 let dateTime=2020-10-10 10:10:10 getDateDiff(dateTime){ let dateTimeStamp = new Date(dateTim ...
- Verilog仿真遇到的问题
1.Vivado 15.4仿真时编译没有报错,但是仿真不成功,逻辑很简单,full为高电平时,rd_en要拉高,但全程没有拉高! 检查语法发现语句" else if( empty == 'b ...
- dockerfile实践学习
一.dockerfile简介 镜像是分层存储的,每一层在前一层的基础上进行修改. 容器也是分层存储,已经向为基础层,在其他基础上加一层作为容器运行的存储层. 创建镜像的另种两种方法 手动修改容器内容, ...
- windows环境下部署项目
有些时候,我们的项目不得不用windows服务器部署,但是需要注意的是,windows服务是无法开启多进程处理请求的. 本文介绍如何在windows上部署flask项目,应用 apache + mod ...
- 如何把高德地图搜索商家电话资料导出成excel里?
有很多人问我地图商家结果采集怎么做? 怎么样能够快速的把高德地图左边的搜索列表里的商家地图,电话,导出到EXCEL里. 如何快速地将高德地图里的商家电话资料导出EXCEL? 操作步骤: 1. 选择你要 ...
- Java实现输出三角形
本来是想实现空心的,想了太久没写出来就算了 代码 package com.qaq.strruct;public class TestDemo01 { //打印三角形 //思路:空格的距离和星星的数量成 ...
- 记录:安装nginx
练习的项目,数据都是跨域获取,上线后就不能再获取到数据,就用到nginx来做代理 注意点: 我用的是阿里云轻量服务器,防火墙在默认情况下是把80端口占据了,然而,安装nginx后,ngi ...
- S-HR查询用户组织范围
SELECT org.FNumber FNumber,org.FName_L2 orgName FROM T_PM_OrgRange orgRange LEFT JOIN T_ORG_admin or ...
- 搭建python+appium环境的时候遇到 'could not find adb.exe!'的问题
搭建Android环境的时候遇到 'could not find adb.exe!'的问题 如果是在的C:\android-sdk-windows\tools目录下并没有adb.exe这个可执行文件. ...
- 前端-对js原型继承的简单举例
function A(name,color){ this.name=name; this.color=color; } A.prototype.getColor=function(){ retur ...


