쿼리 결과를 배치로 처리하기
팀에서는 디지털 결제 행을 하나의 큰 DataFrame으로 수집하는 대신, 청크 단위로 다운스트림 시스템에 전달하려고 합니다. 5,000행씩 배치를 반복하며 각 배치의 간단한 요약 정보를 수집해 보세요.
디지털 결제를 필터링한 LazyFrame digital_rows 가 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Polars로 데이터 파이프라인 확장 및 최적화하기
연습 안내
- 스트리밍 엔진을 사용해
digital_rows를 5,000행씩 배치로 반복 처리하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
batch_summaries = []
# Stream digital_rows in chunks of 5,000
for batch_no, batch in enumerate(
digital_rows.____(chunk_size=____, engine="streaming"),
start=1,
):
batch_summaries.append(
{
"batch": batch_no,
"rows": batch.height,
"checkouts": batch["checkouts"].sum(),
}
)
result = pl.DataFrame(batch_summaries)
print(result)