1 回答
TA贡献1811条经验 获得超4个赞
你在map中使用的函数需要返回你想要的对象。
我还将使用可用于池的更惯用的上下文管理器。
编辑:固定导入
import multiprocessing as mp
def transpose_ope(df): #this function does the transformation like I want
df_op = (df.groupby(['subject_id','readings'])['val']
.describe()
.unstack()
.swaplevel(0,1,axis=1)
.reindex(df['readings'].unique(), axis=1, level=0))
df_op.columns = df_op.columns.map('_'.join)
df_op = df_op.reset_index()
return df_op
def main():
with mp.Pool(mp.cpu_count()) as pool:
res = pool.map(transpose_ope, [df for df in dfs])
if __name__=='__main__':
main()
不知道为什么要将单个列表附加到另一个列表...但是如果您只想要 [transformed(df) for df in dfs] 的最终列表,map 只会返回该列表。
添加回答
举报
