Chapter 5. Eager and Lazy APIs
Now that you have an understanding of the data structures and data types available in Polars, we will look at the two different application programming interfaces (APIs) to interact with that data: the eager API and the lazy API. Each API addresses specific use cases and has unique performance characteristics. Understanding these APIs is critical to using Polars’ data processing and analysis capabilities effectively.
In this chapter, you’ll learn:
-
That the eager API uses an immediate execution model, ideal for data exploration and iterative tasks
-
That the lazy API defers the execution of data transformations until necessary, which allows for comprehensively optimizing queries and improving performance, especially in large-scale and performance-sensitive scenarios
-
About which API fits with which use cases and how to choose the right one for your needs
The instructions to get any files you might need are in Chapter 2. We assume that you have the files in the data subdirectory.
Eager API: DataFrame
The eager API in Polars operates on an immediate execution model, where each function is executed sequentially, line by line, on the dataset. This approach is particularly effective for data exploration and iterative analysis, as it allows for direct interaction with the data at every step. You can execute functions on intermediate results, providing immediate feedback and insights, which is invaluable for making informed decisions about subsequent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access