Group by operations usually reduce the size of a dataframe, both in the number of columns and rows returned. However, sometimes you may want to maintain the original dataframe size.
Below is a dataframe showing different types of groceries bought on each day of the week.
shape: (9, 3)
Day
Product
Price
str
str
f64
"Mon"
"Bread"
3.89
"Tue"
"Milk"
4.0
"Wed"
"Tea"
3.89
"Mon"
"Cheese"
7.99
"Tue"
"Oats"
8.0
"Wed"
"Yogurt"
4.67
"Mon"
"Apple"
4.0
"Tue"
"Juice"
7.89
"Wed"
"Lettuce"
5.99
Group with over
To perform a group by operation while keeping the same dataframe length in Polars, you use the over expression like this: