Skip to content

Instantly share code, notes, and snippets.

@marketneutral
Created July 14, 2020 19:57
Show Gist options
  • Save marketneutral/8fff6db28e899394660813365a6a2488 to your computer and use it in GitHub Desktop.
Save marketneutral/8fff6db28e899394660813365a6a2488 to your computer and use it in GitHub Desktop.

Revisions

  1. marketneutral created this gist Jul 14, 2020.
    11 changes: 11 additions & 0 deletions pandasparapply.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    from joblib import Parallel, delayed

    def expesive_calc(df):
    df['new_col'] = ...
    return df

    def apply_parallel(gdf, func):
    ret_list = Parallel(n_jobs=8)(delayed(func)(group) for name, group in gdf)
    return pd.concat(ret_list)

    df = apply_parallel(df.groupby('grp'), expensive_calc)