Created
May 17, 2020 19:32
-
-
Save romicofre/0057a2e472f454acffeaee689f807193 to your computer and use it in GitHub Desktop.
from multiprocessing import Pool
This file contains hidden or 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
# Function to apply a function over multiple cores | |
@print_timing | |
def parallel_apply(apply_func, groups, nb_cores): | |
with Pool(nb_cores) as p: | |
results = p.map(apply_func, groups) | |
return pd.concat(results) | |
# Parallel apply using 1 core | |
parallel_apply(take_mean_age, athlete_events.groupby('Year'), 1) | |
# Parallel apply using 2 cores | |
parallel_apply(take_mean_age, athlete_events.groupby('Year'), 2) | |
# Parallel apply using 4 cores | |
parallel_apply(take_mean_age, athlete_events.groupby('Year'), 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment