0

Python code:

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

Hi I'm receiving an error: File "C:\Code\study\reducer.py", line 16, in age_balance[balance].append(int(age)) ValueError: invalid literal for int() with base 10: '"age"' The process tried to write to a nonexistent pipe.

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

cavin
  • 5
  • 6

0 Answers0