여러 열로 분할하기
유효하지 않은 행을 DataFrame에서 제거하여 데이터를 상당 부분 정리했어요. 이제 DataFrame의 내용을 바탕으로 의미 있는 열을 생성해, 추가 변환을 수행하려고 합니다.
spark 컨텍스트와 최신 버전의 annotations_df DataFrame이 준비되어 있어요. pyspark.sql.functions는 F라는 별칭으로 사용할 수 있습니다.
이 연습은 강의의 일부입니다
PySpark로 데이터 정제하기
연습 안내
- 탭 문자로
'_c0'열의 내용을 분할하고, 결과를split_cols라는 변수에 저장하세요. - 위 변수의 처음 네 항목을 바탕으로 다음 열을 DataFrame
split_df에 추가하세요: folder, filename, width, height. split_cols변수를 하나의 열로 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Split the content of _c0 on the tab character (aka, '\t')
split_cols = ____(annotations_df['____'], '\t')
# Add the columns folder, filename, width, and height
split_df = annotations_df.withColumn('folder', split_cols.getItem(____))
split_df = split_df.withColumn('filename', ____
split_df = split_df.____
____
# Add split_cols as a column
split_df = split_df.____