安装Spark与python练习
一、安装Spark
1、检查基础环境hadoop,jdk

2、下载spark

3、环境变量

4、运行Python代码

二、Python编程练习:英文文本的词频统计
准备文本文件(f1.txt):
Carter's devotion to her ancestor is about more than personal pride: it is about family honor。 For Josiah Henson has lived on through the character in American fiction that he helped inspire: Uncle Tom, the long-suffering slave in Harriet Beecher Stowe's Uncle Tom's Cabin。 Ironically, that character has come to symbolize everything Henson was not。 A racial sellout unwilling to stand up for himself? Carter gets angry at the thought。 "Josiah Henson was a man of principle," she said firmly。
path='/home/hadoop/cc/f1.txt'
with open(path) as f:
text=f.read()
words = text.split()
cc={}
for word in words:
cc[word]=cc.get(word,0)+1
cclist=list(cc.items())
cclist.sort(key=lambda x:x[1],reverse=True)
print(cclist)
运行结果:


浙公网安备 33010602011771号