PySpark DataFrame 서브셋팅과 정제
데이터를 살펴본 뒤에는 보통 데이터를 정제해야 합니다. 주로 서브셋팅, 열 이름 변경, 중복 행 제거 등이 포함되며, PySpark DataFrame API는 이를 위한 여러 연산자를 제공합니다. 이 연습 문제에서는 people_df DataFrame에서 'name', 'sex', 'date of birth' 열만 추출하고, 그 데이터셋에서 중복 행을 제거한 다음, 중복 제거 전후의 행 개수를 세어 보세요.
워크스페이스에는 이미 SparkSession spark와 DataFrame people_df가 준비되어 있습니다.
이 연습은 강의의 일부입니다
PySpark로 배우는 빅데이터 기초
연습 안내
people_df에서 'name', 'sex', 'date of birth' 열을 선택해people_df_subDataFrame을 만드세요.people_df_subDataFrame에서 처음 10개의 관측치를 출력하세요.people_df_subDataFrame에서 중복 항목을 제거해people_df_sub_nodupDataFrame을 만드세요.- 중복을 제거하기 전과 후에 각각 몇 행이 있나요?
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Select name, sex and date of birth columns
people_df_sub = people_df.____('name', ____, ____)
# Print the first 10 observations from people_df_sub
people_df_sub.____(____)
# Remove duplicate entries from people_df_sub
people_df_sub_nodup = people_df_sub.____()
# Count the number of rows
print("There were {} rows before removing duplicates, and {} rows after removing duplicates".format(people_df_sub.____(), people_df_sub_nodup.____()))