pyspark学习----单词计数小Demo

通过创建SparkConf对象来配置应用,然后基于这个SparkConf创建一个SparkContext对象。驱动器程序通过SparkContext对象来访问Spark。这个对象代表对计算集群的一个连接。一旦有了SparkContext, 就可以用它来创建RDD。

ssh远程访问Linux下的Python解释器

#conding:utf8
from pyspark import SparkConf,SparkContext
from pyspark import conf, context
if __name__ == '__main__':
    conf = SparkConf().setMaster("local[*]").setAppName("wordCountHelloWorld")
    #通过SparkConf对象构建SparkContext对象
    sc = SparkContext(conf=conf)
    file_rdd=sc.textFile("hdfs://192.168.88.161:8020/test/input/wordcount.txt")
    words_rdd=file_rdd.flatMap(lambda  line: line.split(" "))
    words_with_one_rdd=words_rdd.map(lambda x:(x,1))
    result_rdd=words_with_one_rdd.reduceByKey(lambda a,b:a+b)
    print(result_rdd.collect())






 

 pycharm远程查看Linux中文件夹

访问本地的windows的anaconda3——Python解释器,需要安装各种包

pip install pyspark pyhive pymysql jieba -i https://pypi.tuna.tsinghua.edu.cn/simple

在anaconda prompt中安装PySpark环境:

conda create -n pyspark python=3.8

 安装过慢可选用清华镜像源,在windows用户文件夹下创建.condarc文本文件中

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

安装PySpark包

pip install pyspark pyhive pymysql jieba -i https://pypi.tuna.tsinghua.edu.cn/simple

后续在pycharm中配置环境……

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值