Make Pandas DataFrame apply() use all cores?

前端 未结 6 1564
陌清茗
陌清茗 2020-11-27 09:52

As of August 2017, Pandas DataFame.apply() is unfortunately still limited to working with a single core, meaning that a multi-core machine will waste the majority of its com

6条回答
  •  天涯浪人
    2020-11-27 10:40

    If you want to stay in native python:

    import multiprocessing as mp
    
    with mp.Pool(mp.cpu_count()) as pool:
        df['newcol'] = pool.map(f, df['col'])
    

    will apply function f in a parallel fashion to column col of dataframe df

提交回复
热议问题