Anyone working with data knows that encountering null values in a dataset is inevitable. There are several ways to fill null values in Polars. One approach is to replace each null value with the next non-null value that appears after it. Below is a dataframe showing companies and their corresponding company numbers.
shape: (5, 2)
Company
Number
str
i64
"Meta"
null
"Facebook"
1001
"Google"
1020
"OpenAI"
2304
"Oracle"
1022
Fill null with value
To replace null values with the next value that follows them, use the Polars expression backward_fill as shown below: