Monday, November 14, 2022

AI/ML What is Swifter package

Swifter package works with data frame which can be used to apply() function on data frame in an efficient manner. This reduces the computation time to a great extent. From documents it says that it could apply functions 100 times faster compared to regular pandas 

Usually the apply is used 

%time df['square'] = df['num'].apply(lambda x: x * 2)

This takes around 42 ms 

With swifter it is applied like this 

%time df['square'] = df['num'].swifter.apply(lambda x: x * 2)

To import and use this package, below to be done 

import pandas as pd

import swifter

pip install -U pandas

The above is required to update pandas

References:

https://morioh.com/p/26c8b6f1a4a1

No comments:

Post a Comment