CommencerCommencez gratuitement

Creating an Enum column

Movies have a fixed status vocabulary like Released, Rumored, Post Production, and so on. Since the allowed values are known upfront, an Enum is a better fit than Categorical: it adds validation that catches any unknown status before it pollutes the pipeline.

movies is still available, along with a pre-defined status_enum listing every allowed value.

Cet exercice fait partie du cours

<cours>Scaling and Optimizing Data Pipelines with Polars</cours>
Voir le cours

Instructions de l’exercice

  • Cast the status column using the pre-defined status_enum.

Exercice interactif pratique

Essayez cet exercice en complétant ce code d’exemple.

result = movies.with_columns(
    # Cast to the enum
    pl.col("____").____(____)
).select("movie_title", "status").head(8)
print(result)
Modifier et exécuter le code