我是靠谱客的博主 鲜艳洋葱,这篇文章主要介绍用mapreduce 处理气象数据集,现在分享给大家,希望可以做个参考。

编写程序求每日最高最低气温,区间最高最低气温

  1. 气象数据集下载地址为:ftp://ftp.ncdc.noaa.gov/pub/data/noaa
  2. 按学号后三位下载不同年份月份的数据(例如201506110136号同学,就下载2013年以6开头的数据,看具体数据情况稍有变通)
  3. 解压数据集,并保存在文本文件中
  4. 对气象数据格式进行解析
  5. 编写map函数,reduce函数
  6. 将其权限作出相应修改
  7. 本机上测试运行代码
  8. 放到HDFS上运行
    1. 将之前爬取的文本文件上传到hdfs上
    2. 用Hadoop Streaming命令提交任务
  9. 查看运行结果
  10. 复制代码
    1
    2
    3
    4
    5
    6
    7
    8
    cd /usr/hadoop sodu mkdir qx cd /usr/hadoop/qx wget -D --accept-regex=REGEX -P data -r -c ftp://ftp.ncdc.noaa.gov/pub/data/noaa/2017/1* cd /usr/hadoop/qx/data/ftp.ncdc.noaa.gov/pub/data/noaa/2017 sudo zcat 1*.gz >qxdata.txt cd /usr/hadoop/qx

      

    复制代码
    1
    2
    3
    4
    5
    6
    7
    8
    #!/usr/bin/env python import sys for i in sys.stdin: i = i.strip() d = i[15:23] t = i[87:92] print '%st%s' % (d,t)

      

    复制代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    #!/usr/bin/env python from operator import itemggetter import sys current_word = None current_count = 0 word = None for i in sys.stdin: i = i.strip() word,count = i.split('t', 1) try: count = int(count) except ValueError: continue if current_word == word: if current_count > count: current_count = count else: if current_word: print '%st%s' % (current_word, current_count) current_count = count current_word = word if current_word == word: print '%st%s' % (current_word, current_count)

     授予权限 

    复制代码
    1
    2
    3
    chmod a+x /usr/hadoop/qx/mapper.py chmod a+x /usr/hadoop/qx/reducer.py

      

转载于:https://www.cnblogs.com/jm2426330020/p/9016641.html

最后

以上就是鲜艳洋葱最近收集整理的关于用mapreduce 处理气象数据集的全部内容,更多相关用mapreduce内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部