Aan de slagBegin gratis

Using a categorical expression

The team wants a quick flag for movies whose original_language code starts with e (English, Estonian, …). Polars' categorical namespace has its own string-like expressions that work directly on the encoded column, no cast back to String needed.

movies_cat is available with original_language already cast to pl.Categorical.

Deze oefening maakt deel uit van de cursus

Scaling and Optimizing Data Pipelines with Polars

Bekijk cursus

Oefeninstructies

  • Use the categorical namespace to check whether original_language starts with "e".
  • Alias the new boolean column as starts_with_e.

Interactieve oefening met praktijkervaring

Probeer deze oefening door deze voorbeeldcode aan te vullen.

result = movies_cat.select(
    "movie_title",
    "original_language",
    # Flag categorical values starting with "e"
    pl.col("original_language").____.starts_with("____").alias("____"),
).head(8)
print(result)
Code bewerken en uitvoeren