Patrick's 데이터 세상

Swifter 본문

Data Analysis/Processing

Swifter

patrick610 2022. 3. 22. 21:58
반응형
SMALL

 

 

 

 

data 전처리 시에 dataframe, series를 빠르게 apply를 적용하면서 progress bar를 사용할 수 있는 패키지.

 

 

A package which efficiently applies any function to a pandas dataframe or series in the fastest available manner

 

https://pypi.org/project/swifter/

 

swifter

A package which efficiently applies any function to a pandas dataframe or series in the fastest available manner

pypi.org

 


 

👉🏻 설치

pip install swifter

 

 

👉🏻 소스 코드

df['content_swifter'] = df['content'].swifter.apply(lambda x: re.sub(r'\([^]]*\)', '', x))

기본 swifter에 apply 적용한 소스.

 

 

 

  • set_npartitions
    set_npartitions로 cpu 코어 할당이 가능하다.
df['content_swifter'] = df['content'].swifter.set_npartitions(16).apply(lambda x: re.sub(r'\([^]]*\)', '', x))

 

 

 

👉🏻 속도 비교

Pandas apply, Dask apply, Vectorized, swift apply 속도 비교는 아래 공식 사이트에서 확인 할 수 있다.

 

swifter github 문서

 

 

100,000개 데이터 기준 기본 swifter 사용 시 약 0.16초, set_npartitions로 cpu 분배 후 사용 시 약 0.15초로 상승하는 것을 확인하였다.

 

 

 

 

반응형
LIST
Comments