將 production_country 解除巢狀
回到這家串流新創的電影資料集。這次把重點放在 production_country:每一列都包含兩個巢狀欄位,國家代碼與國家名稱。請將這個 struct 解除巢狀,讓這些欄位變成頂層的一般欄位。
本練習屬於課程
使用 Polars 擴充與最佳化資料管線
練習說明
- 將
production_country這個 struct 欄解除巢狀,讓其中的欄位變成一般欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Flatten the struct into columns
result = movies.____("production_country").select(
"movie_title", "code", "name"
).head(8)
print(result)