安装Spark与Python练习

一、Spark的安装

1、安装结果

2、Spark的环境配置

3、运行

4、测试

二、Python练习

1、代码截图

2、运行结果

3、源码

import string

file1 = open('C:/Users/Administrator/R201906120171/Chenzhikun/sanguo.txt', 'r',encoding='UTF-8')
txt = file1.read()
txt.lower()

for ch in string.punctuation:
    txt = txt.replace(ch, " ")
words = txt.split()
result = {}

for word in words:
    result[word] = result.get(word, 0) + 1
items = list(result.items())
items.sort(key=lambda x: x[1], reverse=True)

for i in range(10):
    print(items[i])
file2 = open('result.txt', 'w')

for i in items:
    for j in i:
        file2.write(str(j)+" ")
    file2.write("\n")

file1.close()
file2.close()
posted @ 2022-03-06 21:53  Orlando_Chan  阅读(28)  评论(0编辑  收藏  举报