시작하기무료로 시작하기

DataFrame 캐시하기

여러 분석 연산을 같은 DataFrame에 대해 여러 번 실행해야 하는 작업이 주어졌어요. DataFrame을 재사용할 때 캐시를 사용하면 성능이 향상된다는 것을 배웠으니, 이를 적용해 보려고 합니다.

항공편 출발 정보로 구성된 새로운 데이터셋으로 작업하게 됩니다. 중복 데이터가 있을 수 있어 중복을 제거해야 합니다.

DataFrame departures_df는 이미 정의되어 있으나, 아직 어떤 액션도 수행하지 않았습니다.

이 연습은 강의의 일부입니다

PySpark로 데이터 정제하기

강의 보기

연습 안내

  • departures_df DataFrame에서 고유 행을 캐시하세요.
  • departures_df에 대해 count 쿼리를 실행하고, 작업에 걸린 시간을 기록하세요.
  • 캐시된 DataFrame에서 다시 한 번 행 수를 세고, 소요 시간의 차이를 확인하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

start_time = time.time()

# Add caching to the unique rows in departures_df
departures_df = departures_df.____.____

# Count the unique rows in departures_df, noting how long the operation takes
print("Counting %d rows took %f seconds" % (departures_df.____, time.time() - start_time))

# Count the rows again, noting the variance in time of a cached DataFrame
start_time = time.time()
print("Counting %d rows again took %f seconds" % (____, time.time() - start_time))
코드 편집 및 실행