swifter
A package which efficiently applies any function to a pandas dataframe or series in the fastest available manner
Installation:
$pip install swifter # first time installation
$pip install -U swifter # upgrade to latest version
and then import into your code using:
from swifter import swiftapply
Easy to use
myDF['outCol'] = swiftapply(myDF['inCol'], my_func)
myDF['outCol'] = swiftapply(myDF['inCol'], my_func, positional_arg, keyword_arg=keyword_argval)
Check out the examples notebook, along with the speed benchmark notebook
Vectorizes your function, when possible
When vectorization is not possible, automatically decides which is faster: to use dask parallel processing or a simple pandas apply
Notes
-
The function is documented in the .py file. In Jupyter Notebooks, you can see the docs by pressing Shift+Tab(x3). Also, check out the complete documentation here along with the changelog.
-
When using swiftapply on a dataframe with a non-vectorized function call, swiftapply will resort to concatenating swiftapplies on each column because dask applymap does not work properly as of now. Submitting a bug fix shortly.