r/Python • u/silicon_turfsurfer • 2h ago
Discussion Polars for data-heavy datasets
A few months back I switched from pandas to polars because some of the datasets I needed to work with were hitting the million row mark and beyond. It has taken quite some time to get used to the more verbose polars dataframe methods but I have to say I am really pleased with the execution speed improvement.
I also moved away from applying filters and calculating, migrating to the group_by.agg() for performing row calculations - HUGE difference in speed.
For those of you who haven't heard of polars, it is multi-threaded whereas pandas is single-threaded, so for large datasets it is faster. I would never have made the switch were it not for large datasets, and I frequently convert to pandas dataframes when debugging.
Anyone else have similar experiences or have resisted the urge to migrate away from pandas?
29
u/Gigawrench 2h ago
My experience is that, once you get familiar with the polars APIs, the developer ergonomics for dataframe manipulation are so much more intuitive and expressive than pandas. Big fan of the lazyframe functionality where you can lean on the built-in optimisation engine to do a lot of the performance tuning for a given operation.
11
u/lolcrunchy 2h ago
This is very timely. I just rewrote a pandas data process to polars LazyFrames with collect_all() at the end. The execution time went from 4-5 hours to a few minutes.
5
u/king_escobar 2h ago
Pandas is obsolete technology, nobody should be using Pandas anymore. Polars is that much better.
•
u/Justbehind 24m ago
Polars is superior in every way. Easier to write and read, and performance is so much better.
We are working with datasets in the 100s of millions of rows on our laptops. Effectively.
1
u/Mcletters 2h ago
Any tips on ways to learn, tutorials, etc?
•
u/Late-Photograph-1954 39m ago
I moved to DuckDb and SQL. My auditor much prefers to review Sql and AI crafts the most brilliant SQL queries instantly.