이터레이터로 대용량 파일을 메모리에 로드하기

Python 도구 상자

Hugo Bowne-Anderson

Data Scientist at DataCamp

청크로 데이터 로드하기

  • 메모리에 담기엔 데이터가 너무 클 수 있습니다
  • 해결: 데이터를 청크로 로드합니다!
  • pandas 함수: read_csv()
    • 청크 크기 지정: chunksize
Python 도구 상자

데이터 반복 처리

import pandas as pd
result = []

for chunk in pd.read_csv('data.csv', chunksize=1000):
result.append(sum(chunk['x']))
total = sum(result)
print(total)
4252532
Python 도구 상자

데이터 반복 처리

import pandas as pd
total = 0

for chunk in pd.read_csv('data.csv', chunksize=1000): total += sum(chunk['x'])
print(total)
4252532
Python 도구 상자

연습해 봅시다!

Python 도구 상자

Preparing Video For Download...