시작하기무료로 시작하기

파티션 수가 다른 경우의 ID

방금 DataFrame에 ID 필드를 추가했어요. 이제 파티션 수가 다른 DataFrame에 같은 작업을 하면 어떻게 되는지 살펴보세요.

파티션 수를 확인하려면 DataFrame에 대해 .rdd.getNumPartitions() 메서드를 사용하세요.

작업 공간에는 spark 세션과 두 개의 DataFrame인 voter_df, voter_df_single이 준비되어 있어요. 지침을 따라 두 DataFrame 간의 차이를 확인해 보세요. pyspark.sql.functions 라이브러리는 별칭 F로 임포트되어 있어요.

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

PySpark로 데이터 정제하기

강의 보기

연습 안내

  • 각 DataFrame의 파티션 수를 출력하세요.
  • 각 DataFrame에 ROW_ID 필드를 추가하세요.
  • 각 DataFrame에서 상위 10개의 ID를 확인해 출력하세요.

실습형 인터랙티브 연습

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

# Print the number of partitions in each DataFrame
print("\nThere are %d partitions in the voter_df DataFrame.\n" % ____)
print("\nThere are %d partitions in the voter_df_single DataFrame.\n" % ____)

# Add a ROW_ID field to each DataFrame
voter_df = voter_df.____('ROW_ID', ____)
voter_df_single = ____

# Show the top 10 IDs in each DataFrame 
voter_df.____(voter_df.____.desc()).show(____)
____.orderBy(____).show(10)
코드 편집 및 실행