如何修改此代码,以便当 senti_avg 不可整除(0/值)时,reducer() 输出 NULL 或 NONE 而不是崩溃?
def reducer(self, bs_id, value):
avg_data = list(value)
senti_sum = sum([a[0] for a in avg_data])
word_sum = sum([a[1] for a in avg_data])
senti_avg = senti_sum/float(word_sum)
yield (bs_id, senti_avg)