국가 필드 이름 변경하기
struct 필드인 code 와 name 은 보고서에 사용하기에는 이름이 너무 범용적입니다. 먼저 각각 country_code 와 country_name 으로 이름을 변경한 다음, struct를 펼치세요.
이전과 동일한 movies DataFrame을 사용합니다.
이 연습은 강의의 일부입니다
Polars로 데이터 파이프라인 확장 및 최적화하기
연습 안내
- struct의 필드 이름을 변경하는 적절한 메서드를 사용하세요.
- 순서에 맞게
country_code,country_name으로 이름을 지정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
result = (
movies
.with_columns(
# Rename the two struct fields
pl.col("production_country")
.struct.____(["____", "____"])
.alias("production_country")
)
.unnest("production_country")
.select("movie_title", "country_code", "country_name")
.head(8)
)
print(result)