텍스트 열 분리와 펼치기
100개의 행을 가진 데이터프레임 clauses_df가 제공됩니다. 이 데이터프레임에는 clause 열과 행 ID가 있습니다. 각 clause는 공백으로 구분된 하나 이상의 단어로 이루어진 문자열입니다.
이 연습은 강의의 일부입니다
Python에서 Spark SQL 입문
연습 안내
clause열을 분리해 개별 단어의 배열을 담는words열을 만드세요.words열을 펼쳐서word라는 열로 변환하세요.- 그 결과로 생기는 행의 개수를 세세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Split the clause column into a column called words
split_df = clauses_df.select(____('clause', ' ').____('words'))
split_df.show(5, truncate=False)
# Explode the words column into a column called word
exploded_df = split_df.____(____('____').____('word'))
exploded_df.show(10)
# Count the resulting number of rows in exploded_df
print("\nNumber of rows: ", ____)