mapreduce 处理气象数据集

本文介绍了如何使用Hadoop进行数据处理的过程,包括从FTP下载数据文件到本地Hadoop目录,并利用Python脚本作为Mapper和Reducer进行数据处理。此外,还展示了如何通过命令行操作来解压并整合数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

#!/usr/bin/env python
import sys
for i in sys.stdin:
     i = i.strip()
     d = i[15:23]
     t = i[87:92]

     print '%s\t%s' % (d,t) 

#!/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 '%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)

chmod a+x /usr/hadoop/qx/mapper.py
chmod a+x /usr/hadoop/qx/reducer.py

 

转载于:https://www.cnblogs.com/lk666/p/9016884.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值