2.安装Spark与Python练习

一、安装spark和python练习

 

查看spark所在的位置

开启spark所需要的节点

查看配置文件

开启spark并进行简单python语句测试

 

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

 

代码:

 1 path='/home/hadoop/桌面/ysy.txt' 
 2 f=open(path)          #读取文件
 3 with open(path) as y: 
 4     text=y.read()    #预处理
 5 words = text.split()  #分词
 6 wc={} 
 7 for word in words:     #统计单词出现的次数
 8     wc[word]=wc.get(word,0)+1 
 9 wclist=list(wc.items()) 
10 wclist.sort(key=lambda x:x[1],reverse=True)  #按照词频大小排序
11 print(wclist)

 

运行截图:

 

posted @ 2022-03-01 18:14  箫碧栽植  阅读(61)  评论(0)    收藏  举报