Chapter 7. Beginning Expressions
The goal of this chapter is to introduce expressions, which are what makes the Polars API so powerful and elegant. This chapter forms the basis for the remaining chapters of Part III, “Express”, where we go into more detail regarding specific expressions and how to use them.
Polars Expressions versus Regular Expressions
Polars expressions should not be confused with regular expressions.
A regular expression, or regex, is a sequence of characters that is used to match text.
For example, the regex [Pp](ol|and)ar?s
matches both pandas
and Polars
, but it doesn’t match panda
or polaris
.
A few Polars methods do accept regexes, such as pl.col()
for selecting columns and Expr.str.replace()
for replacing values.
The interactive website RegExr by Grant Skinner and the book Introducing Regular Expressions by Michael FitzGerald (O’Reilly, 2012, 978-1449392680) are useful resources for learning more about regexes. ...
Get Python Polars: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.