Created
July 14, 2020 19:57
-
-
Save marketneutral/8fff6db28e899394660813365a6a2488 to your computer and use it in GitHub Desktop.
Pandas Parallel Appy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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