BaşlayınÜcretsiz başlayın

Renaming country fields

The struct fields code and name are too generic for reports. Rename them to country_code and country_name first, then unnest.

You're still working with the same movies DataFrame.

Bu egzersiz, kursun bir parçasıdır

Scaling and Optimizing Data Pipelines with Polars

Kursa Göz Atın

Egzersiz talimatları

  • Use the right method on the struct to rename its fields.
  • Name them country_code and country_name, in that order.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

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)
Kodu Düzenle ve Çalıştır