Aan de slagBegin gratis

Counting genres per movie

The team also wants a quick summary column that counts how many genres are listed for each movie. Use a list expression to create genre_count.

You're still working with the same movies DataFrame.

Deze oefening maakt deel uit van de cursus

Scaling and Optimizing Data Pipelines with Polars

Bekijk cursus

Oefeninstructies

  • Count the number of genres in each row's genres list.
  • Alias the new column as genre_count.

Interactieve oefening met praktijkervaring

Probeer deze oefening door deze voorbeeldcode aan te vullen.

result = movies.select(
    "movie_title",
    "genres",
    # Count the genres
    pl.col("genres").list.____().alias("____"),
).head(8)
print(result)
Code bewerken en uitvoeren