2.安装Spark与Python练习
一、安装Spark
- 检查基础环境hadoop,jdk
![]()
- 下载spark
之前课程已经做好
- 解压,文件夹重命名、权限
之前课程已经做好
- 配置文件
![]()
![]()
![]()
- 环境变量
![]()
![]()
- 试运行Python代码
![]()
![]()
二、Python编程练习:英文文本的词频统计
- 准备文本文件
![]()
- 读文件
![]()
- 预处理:大小写,标点符号,停用词
![]()
- 分词
![]()
- 统计每个单词出现的次数
![]()
- 按词频大小排序
![]()
- 结果写文件
path='/home/hadoop/wc/111.txt' with open(path) as f: text=f.read() text = text.lower() text = text.replace(",", " ").replace(".", " ").replace("!", " ") text = text.strip() words = text.split() wc={} for word in words: wc[word]=wc.get(word,0)+1 wclist=list(wc.items()) wclist.sort(key=lambda x:x[1],reverse=True) txt = open("222.txt","w",encoding='UTF-8') txt.write(str(wclist)) print(wclist)![]()
![]()
![]()
![]()

















浙公网安备 33010602011771号