Applying logic to each element in lists
One of Polars’s strengths is the ability to work well with nested structures. It not only helps with aggregations, as well as selecting and accessing elements in lists but also helps you apply simple to complex logic to each element in a list. This gives you the flexibility and power to transform your data in an efficient manner utilizing Polars’s optimizations.
In this recipe, we’ll cover how you can apply transformation logic to each element in a list.
Getting ready
We’ll be using a pre-aggregated DataFrame for this recipe. We will aggregate views, likes, and channel titles by trending date:
agg_df = (     df     .group_by('trending_date')     .agg('views', 'likes', 'channel_title') ) agg_df.head()
The preceding code will return the following output:
Figure 7.20 – A DataFrame...