国フィールドの名前変更
struct のフィールド code と name は、レポートに使うには名前が汎用的すぎます。まず country_code と country_name に名前を変更してから、アンネストしましょう。
ここでも同じ 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)