Python 2020. 3. 18. 22:21

흔히 말하는 Big data 크기의 데이터를 다룰 일이 거의 없다보니 pandas를 이용해서 data를 load 하고 사용하는데 크게 불편한적은 없었다. 다만 이것저것 준비하는 과정에서 수십기가짜리 csv파일을 read_csv로 그냥 호출하면 메모리가 터지는 경우를 자주 볼 수 있었다. 그러다 찾은것이 바로 chunk size!

 

pandas에 read_csv를 보면 chunksize라는 파라미터가 있다. 

import pandas as pd
df_chunk = pd.read_csv(r'/inputpath/file.csv', iterator=True, chunksize=1000000)

df = pd.concat([chunk for chunk in df_chunk])

 

아래 사이트에서 잘 설명중

http://acepor.github.io/2017/08/03/using-chunksize/

 

Using Chunksize in Pandas

Yet another blog about NLP, machine learning and programming

acepor.github.io

 

posted by 초코렛과자
: