zoukankan      html  css  js  c++  java
  • 用mapreduce 处理气象数据集

    用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. 查看运行结果
      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/6*
       
      cd /usr/hadoop/qx/data/ftp.ncdc.noaa.gov/pub/data/noaa/2017
      sudo zcat 1*.gz >qxdata.txt
      cd /usr/hadoop/qx
       
       
      import sys
      for i in sys.stdin:
           i = i.strip()
           d = i[15:23]
           t = i[87:92]
       
           print '%s	%s' % (d,t)
       
      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('	', 1)
           try:
                count = int(count)
           except ValueError:
                continue
       
           if current_word == word:
               if current_count > count:
                    current_count = count
           else:
               if current_word:
                   print '%s	%s' % (current_word, current_count)
               current_count = count
               current_word = word
       
      if current_word == word:
           print '%s	%s' % (current_word, current_count)
       
      chmod a+x /usr/hadoop/qx/mapper.py
      chmod a+x /usr/hadoop/qx/reducer.py
      

        

  • 相关阅读:
    Ignatius and the Princess II(全排列)
    中缀式变后缀式
    前缀式计算(前缀表达式)
    Mysql中的锁机制详解
    Mysql关于事务并发带来的问题
    第三方实用API接口汇总
    Mysql 性能优化Explain详解
    Mysql性能分析工具 SHOW PROFILE、 SHOW STATUS
    Mysql慢查询分析
    【数字图像处理】霍夫变换实现
  • 原文地址:https://www.cnblogs.com/206cch/p/9016891.html
Copyright © 2011-2022 走看看