编程语言
首页 > 编程语言> > 2.安装Spark与Python练习

2.安装Spark与Python练习

作者:互联网

一、安装Spark

1.检查基础环境hadoop,jdk

 

 

 

2.下载spark

(已完成,略过)

3.解压,文件夹重命名、权限

(已完成,略过)

4.配置文件

(已完成,略过)

5.环境变量

 

 

 6.试运行Python代码

 

 

 

 

 

二、Python编程练习:英文文本的词频统计

1.准备文本文件

 

 

 

 

 

 

 

 2.读文件

path='/home/hadoop/lh.txt' with open(path) as f:     text=f.read()   3.预处理:大小写,标点符号,停用词,分词 words = text.lower().split() for in '!"#$%^&*()_+-=@[]{}|\?/<>,.:;~·`、“”‘’':       text = text.replace(c, " ") t={}   4.统计每个单词出现的次数,词频大小排序 for word in words:     t[word]=t.get(word,0)+1 tlist=list(t.items()) tlist.sort(key=lambda x:x[1],reverse=True) print(tlist)   5.结果写文件 text = open("lh.txt""w", encoding='UTF-8') text.write(str(tlist))

 

 


 

标签:word,Python,text,略过,练习,词频,tlist,Spark
来源: https://www.cnblogs.com/usershino/p/15973019.html