我正在编写一个简单的地图减少程序,它统计体育赛事期间每天发送的推文数量。
def mapper(self,_,line):
#Extracting the fields of csv line
fields = line.split(";")
#To choose the actual tweet we extract field[4]
for field[4] in fields:
time_epoch = int(fields[0])/1000
#Extract date tweet was sent
day = time.strftime("%d",time.gmtime(time_epoch))
#For each date, count num of tweets sent
#Since calculating the number of tweets sent each day
#Shouldn't day be the key, and intermediate value be 1
yield(day, 1)现在,还原器代码接受中间键,值并执行聚合:
def reducer(self, day, counts):
#For each day during the sporting event, calculate the total tweets sent
yield(day, sum(counts))I正在艰难地决定到底是实际的推文还是发送推文的日期是还原剂的关键。但是,我得出的结论是,由于我想计算每天的总数,所以具体的一天应该是关键。
然而,我得到了一个错误,我想知道是否有明显的东西,我错过了?非常感谢!
发布于 2018-10-25 21:51:14
您没有提到错误,但是for field[4] in fields:在语法上是不正确的。
也许你是说if len(fields) >= 4:
然而,我得出的结论是,既然我要计算每天的总数,那么具体的一天就应该是关键。
这对我来说是对的
https://stackoverflow.com/questions/52986921
复制相似问题