Python线程错误-必须是iterable,而不是

2024-06-13 05:57:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图计算数据帧中第一列和其他列(第一列和第二列、第一列和第三列等)之间回归的滚动r平方,但当我尝试线程时,它一直告诉我错误是

TypeError: ParallelRegression() argument after * must be an iterable, not int".

我在想我该怎么解决这个问题?非常感谢!

import threading

totalThreads=3 #three different colors
def ParallelRegression(threadnum):
    for i in range(threadnum):
        res[:,i]=sm.OLS(df.iloc[:,0], df.iloc[:,i+1]).fit().rsquared
threads=[]
for threadnum in range(totalThreads):
    t=threading.Thread(target=ParallelRegression,args=(threadnum))
    threads.append(t)
    t.start()
for threadnum in range(totalThreads):
    threads[threadnum].join()

请参阅下面链接的图片中的数据摘要(df):

enter image description here


Tags: 数据indffor错误rangeargument线程
1条回答
网友
1楼 · 发布于 2024-06-13 05:57:39

threading.Thread类需要一个iterable参数作为args参数。您传递的是一个args=(threadnum)对象,您需要传递一些允许多个参数的iterable对象,即使您只想传递一个参数。

args=[threadnum]会起作用,因为这使得一个list是可接受的。

相关问题 更多 >