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. 查看运行结果
      import sys
      
      for line in sys.stdin:
          line = line.strip()
          print('%s	%d' % (line[15:23], int(line[87:92])))
      from operator import itemgetter
      import sys
      
      current_date = None
      current_temperature = 0
      date = None
      
      for line in sys.stdin:
          line = line.strip()
          date, temperature = line.split('	', 1)
          try:
              temperature = int(temperature)
          except ValueError:
              continue
      
          if current_date == date:
              if current_temperature < temperature:
                  current_temperature = temperature
          else:
              if current_date:
                  print('%s	%d' % (current_date, current_temperature))
              current_temperature = temperature
              current_date = date
      
      if current_date == date:
          print('%s	%d' % (current_date, current_temperature))
      chmod a+x mapper.py 
      chmod a+x reducer.py 
      cat test.txt | python mapper.py | python reducer.py 
  • 相关阅读:
    关于react fiber的理解
    前段框架——VueX
    前段框架——Vue组件间传值
    前段框架——Vue的get和post请求数据
    前段框架——Vue的一级路由和二级路由
    前端框架——Vue脚手架
    前段框架——Vue
    关于Tomcat的BUG
    验证身份证号格式
    mysql 占用90%多的CPU,解决思路
  • 原文地址:https://www.cnblogs.com/168-hui/p/9016609.html
Copyright © 2011-2022 走看看