Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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