728x90
tqdm 은 for 문을 처리할때
진행률을 표시해주는 파이썬 라이브러리이다.
하지만 pandas 에서 열전체의 함수를 매기는 map 이나 데이터프레임 전체에 함수를 매기는 apply 의 경우
많은 데이터의 실행을 했을 때 진행률을 알 수 없고
주피터에서 * 표시만 계속 쳐다볼뿐이다.
그래서 pandas 의 map 함수와 apply 함수의 진행률을 볼 수 있는 방법을 공유한다.
apply
import pandas as pd
import numpy as np
from tqdm import tqdm
# from tqdm.auto import tqdm # for notebooks
df = pd.DataFrame(np.random.randint(0, int(1e8), (10000, 1000)))
# Create new `pandas` methods which use `tqdm` progress
# (can use tqdm_gui, optional kwargs, etc.)
tqdm.pandas()
# Now you can use `progress_apply` instead of `apply`
df.groupby(0).progress_apply(lambda x: x**2)
MAP
def sum_two(x):
return x + 2
df['colName'] = df['colName'].progress_map(sum_two)
tqdm 4.8 버전 이하는
from tqdm import tqdm, tqdm_pandas
tqdm_pandas(tqdm())
참고 : stackoverflow.com/questions/18603270/progress-indicator-during-pandas-operations
반응형
'Machine learning' 카테고리의 다른 글
[설치]. 윈도우 하위 시스템 WSL 셋팅하기 (0) | 2021.07.18 |
---|---|
[설치]. 리눅스 환경에서 Anaconda 설치하기 (0) | 2021.07.18 |
[기계 학습]. SGD 와 mini batch ( 최적화 기법 ) (0) | 2021.03.22 |
[기계 학습] sklearn.pipeline 파이프 라인 (0) | 2021.02.10 |
[데이터 전처리]. 날짜 데이터 전처리 (0) | 2021.02.09 |