Skip to main content
 首页 » 编程设计

python之类型错误 : object of type 'IMapIterator' has no len() for pool. imap

2024年12月31日23pander-it

我收到以下错误:

df_OP = pd.DataFrame([excel_write_data[idx].__dict__ for idx in range(0,  
len(excel_write_data))]) 
 
TypeError: object of type 'IMapIterator' has no len(). 

我正在使用 imap 进行并行处理,但出现上述错误

excel_write_data = pool.imap(pre_process, excel_read_data) 

我怎样才能克服这个错误。谁能帮忙

请您参考如下方法:

因此 IMapIterator 是一个可迭代对象,但您需要一些类似于列表的东西(具有 len())。因此,将其列为一个列表:

excel_write_data = list(pool.imap(pre_process, excel_read_data))