Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marketneutral
Created July 14, 2020 19:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marketneutral/8fff6db28e899394660813365a6a2488 to your computer and use it in GitHub Desktop.
Save marketneutral/8fff6db28e899394660813365a6a2488 to your computer and use it in GitHub Desktop.
Pandas Parallel Appy
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment