用mapreduce 處理氣象資料集

2022-08-26 00:21:27 字數 1431 閱讀 7990

用mapreduce 處理氣象資料集

編寫程式求每日最高最低氣溫,區間最高最低氣溫

3.解壓資料集,並儲存在文字檔案中

cd /usr/hadoop

sodu mkdir qx

cd /usr/hadoop/qx

wget -d --accept-regex=regex -p data -r -c

cd /usr/hadoop/qx/data/ftp.ncdc.noaa.gov/pub/data/noaa/2017

sudo zcat 1*.gz >qxdata.txt

cd /usr/hadoop/qx

4.對氣象資料格式進行解析

5.編寫map函式,reduce函式

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

使用 vim reducer.py 編寫reduce函式

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

6.將其許可權作出相應修改

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

7.本機上測試執行**

8.放到hdfs上執行

將之前爬取的文字檔案上傳到hdfs上

用hadoop streaming命令提交任務

9.檢視執行結果

用mapreduce 處理氣象資料集

用mapreduce 處理氣象資料集 編寫程式求每日最高最低氣溫,區間最高最低氣溫 解壓資料集,並儲存在文字檔案中 對氣象資料格式進行解析 編寫map函式,reduce函式 將其許可權作出相應修改 本機上測試執行 放到hdfs上執行將之前爬取的文字檔案上傳到hdfs上 用hadoop streami...

用mapreduce 處理氣象資料集

編寫程式求每日最高最低氣溫,區間最高最低氣溫 解壓資料集,並儲存在文字檔案中 對氣象資料格式進行解析 編寫map函式,reduce函式 將其許可權作出相應修改 本機上測試執行 放到hdfs上執行將之前爬取的文字檔案上傳到hdfs上 用hadoop streaming命令提交任務 檢視執行結果12 3...

用mapreduce 處理氣象資料集

本次的所有操作均在當前使用者目錄下的 temp 2018 05 09中 wget drc accept regex regex p data 在這之前,需要配置好環境,在.bashrc中加入下面的命令 export path path usr local hbase bin usr local ha...