2.安装Spark与Python练习
作者:互联网
一、安装Spark
1、检查基础环境hadoop,jdk
echo $JAVA_HOME java -version start-dfs.sh jps hadoop version
2、配置文件
cp ./conf/spark-env.sh.template ./conf/spark-env.sh gedit ./conf/spark-env.sh
3、环境变量
gedit ~/.bashrc
4、试运行Python代码
print('spark') 8*2-5 sc
二、Python编程练习:英文文本的词频统计
1、准备文本文件
cd ~/wc gedit f1.txt
2、读文件、预处理、分词、统计每个单词出现的次数、按词频大小排序
wc.py:
path='/home/hadoop/wc/f1.txt' with open(path) as f: text=f.read() 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) print(wclist)
3、结果写文件
gedit wc.py python3 wc.py
标签:wc,Python,练习,wclist,gedit,sh,conf,Spark,spark 来源: https://www.cnblogs.com/sealion/p/15954051.html