对于数据的平均值处理:
def checkstr(mystr): try: num=eval(mystr) return True except: return False file=r"D:python爬虫视频爬虫代码处理爬虫数据排序 asa.txt" readfile=open(file,"rb") myfilelist=readfile.readlines() #print(myfilelist) i=0 numavers=0 for average in myfilelist: average=average.decode("gbk","ignore") aver=average.split(" ") if len(aver)>19: if checkstr(aver[4]): if len(aver[4])==3: i+=1 avers=int(aver[4]) numavers+=avers #print(i) #print(avers) average=numavers/i print(average)