类型错误:'int'对象不可迭代 - 使用 POOL 进行多处理



我试图读取一个csv文件并找到列的平均值。无法破解池多处理部分! 不断为多处理部分给出错误。串行处理正在工作!

import os
from multiprocessing import Pool
import pandas as pd
import time
import statistics
def average(listed_marks):
avg=[]
i=[]
for i in listed_marks:
avg.append(statistics.mean(i))
return avg

if __name__ == '__main__':
list_of_marks=[]  
df = pd.read_csv(r"C:UsersRadhikaDesktopRADZ ProjectsXoriantdata.csv")
n = df['STUDENT ID'].count() #no of rows
for i in range(n):  #to obtain the list of lists
a=list(df.iloc[i , 3:6])
a = list(map(int, a)) #converting the lists into int to perform mean
list_of_marks.append(list(a))
# ---------------------MP---------------------------------------------------
s1= time.time()    
p = Pool()
avg_mp = p.map(average, list_of_marks) #passed the average function and iterator is a list of list
df['Average'] = avg_mp
p.close()
p.join()
print(f"Processing took {time.time() - s1} using Multi-Processing")

看起来你的 average(( 函数应该只是:

def average(listed_marks):
return statistics.mean(listed_marks)

相关内容

  • 没有找到相关文章

最新更新