shape: (3, 2)
| Represent | Value |
|---|---|
| str | i64 |
| "Area code" | 563 |
| "Exchange code" | 384 |
| "Line number" | 9905 |
str.join
Joram Mutenge
2025-12-20
Polars allows you to collapse multiple rows into a single row, combining the values from all the rows into one. Below is a dataframe showing parts of a phone number.
| Represent | Value |
|---|---|
| str | i64 |
| "Area code" | 563 |
| "Exchange code" | 384 |
| "Line number" | 9905 |
We can construct the full phone number from the three rows using the Polars expression str.join like this:
| Phone_No |
|---|
| str |
| "563-384-9905" |
This is different from the implode function, which returns a list of values instead of a string.
| Phone_No |
|---|
| list[i64] |
| [563, 384, 9905] |
Check out my Polars course to learn more.