用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('\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 '%s\t%s' % (current_word, current_count)
         current_count = count
         current_word = word
 
if current_word == word:
     print '%s\t%s' % (current_word, current_count)

  

修改权限

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

  

posted @ 2018-05-09 21:56  lawliet9  阅读(150)  评论(0编辑  收藏  举报