Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

As of August 2017, Pandas DataFame.apply() is unfortunately still limited to working with a single core, meaning that a multi-core machine will waste the majority of its compute-time when you run

df.apply(myfunc, axis=1).

How can you use all your cores to run apply on a dataframe in parallel? 

1 Answer

0 votes
by (41.4k points)
edited by

Using this below code will apply function f in a parallel fashion to column col of dataframe df:

import multiprocessing as mp

pool = mp.Pool(mp.cpu_count())

df['newcol'] = pool.map(f, df['col'])

pool.terminate()

pool.join()

If you want to make your career in Artificial Intelligence then go through this video:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 24, 2019 in Data Science by ashely (50.2k points)

Browse Categories

...