python mapreduce-平均

时间:2018-11-30 12:18:03

标签: python mapreduce key average

Python代码:

#!/usr/bin/python
#Reducer.py
import sys

age_balance = {}

#Partitoner
for line in sys.stdin:
    line = line.strip()
    age, balance = line.split('\t')

    if age in age_balance:
        age_balance[age].append(int(balance))
    else:
        age_balance[age] = []
        age_balance[age].append(int(balance))

#Reducer
for age in age_balance.keys():
    ave_age = sum(age_balance[age])*1.0 / len(age_balance[age])
    print '%s\t%s'% (age, ave_age)

嗨,我收到一个错误: 文件“ C:\ Code \ study \ reducer.py”,第16行,在age_balance [balance] .append(int(age))中ValueError:int()的无效文字,基数为10:““ age”' 该过程试图写入不存在的管道。

This is a sample of the data im trying to get average of :

0 个答案:

没有答案