zoukankan      html  css  js  c++  java
  • 用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. 查看运行结果
    1
    2
    3
    4
    5
    6
    7
    8
    9
    cd /usr/hadoop
    sodu mkdir qx
    cd /usr/hadoop/qx
     
    wget ---accept-regex=REGEX -P data --c ftp://ftp.ncdc.noaa.gov/pub/data/noaa/2014/5* 
     
    cd /usr/hadoop/qx/data/ftp.ncdc.noaa.gov/pub/data/noaa/2014
    sudo zcat 1*.gz >qxdata.txt
    cd /usr/hadoop/qx
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    #!/usr/bin/env python
    from operator import itemggetter
    import sys
     
    current_word = None
    current_count = 0
    word = None
     
    for in sys.stdin:
         = 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)

      

    修改权限

    1
    2
    chmod a+/usr/hadoop/qx/mapper.py
    chmod a+/usr/hadoop/qx/reducer.py

      

  • 相关阅读:
    Legendary Items-微软2017实习生笔试第一题
    (转载)华为离职副总裁徐家骏:年薪千万的工作感悟
    【AtCoder Regular Contest 092】C.2D Plane 2N Points【匈牙利算法】
    poj 2236【并查集】
    poj 2431 【优先队列】
    poj 3280【区间dp】
    uva 10453 【回文串区间dp】
    uva 10739【基础(区间)dp】
    poj 2385【动态规划】
    poj 2229 【完全背包dp】【递推dp】
  • 原文地址:https://www.cnblogs.com/lawliet12/p/9016924.html
Copyright © 2011-2022 走看看