News for hackers. Stuff that matters.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by jeroenjanssens on Tuesday August 18, 2026 @09:38AM (#49345477)
We spent the last few weeks compressing our book, Python Polars: The Definitive Guide (nearly 500 pages), down to a two-page cheatsheet. It's a highly lossy compression, but hopefully a useful one! Besides the PDF, there's also an accessible HTML version.

We're curious to hear what you think. Let us know if we missed any of your favorite Polars operations, or if you have any feedback on how we organized it.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by grim_io on Tuesday August 18, 2026 @10:19AM (#49345998)
Is there an .MD version? For, uh, reasons :)
Re:Python Polars Cheatsheet (based on our O'Reilly book) by jeroenjanssens on Tuesday August 18, 2026 @12:06PM (#49347837)
Yes, opensource.posit.co is entirely open source :)

https://github.com/posit-dev/open-source-website/blob/main/c...

Re:Python Polars Cheatsheet (based on our O'Reilly book) by qrobit on Tuesday August 18, 2026 @10:45AM (#49346378)
I believe the complete HTML version is right below the "Download PDF" button. Also I bet you could reproduce the cheatsheet using this HTML converted to markdown and some example from how other Posit (formerly RStudio) cheatsheets are made: https://github.com/rstudio/cheatsheets/tree/main/html
Re:Python Polars Cheatsheet (based on our O'Reilly book) by clircle on Tuesday August 18, 2026 @10:15AM (#49345946)
I get that the data science world has moved on to python, but I always felt that R's data.table had the slickest dataframe developer experience. I have toyed with Polars for a few hours, maybe I should give it a better chance.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by dec0dedab0de on Tuesday August 18, 2026 @12:16PM (#49347981)
I first learned about R at a python user group meeting. It was when Pandas was new, and we were having a bunch of talks about it. Wes McKinney even came to give one before going to Pycon. Anyway, the general consensus at the time was that R was much nicer once you had your data, and if all you had to do was transform it. But that everything else was better in Python. One of our group members did an experimental project, where you could open R inside of python and share memory. So you could theoretically do your API calls and screen scraping and whatnot in Python, then transform your data in R, then take the output and use it to do something else in Python. It was pretty cool, but I think it was just a POC and never really went anywhere.

I tried learning R after that, but didn't get very far with it.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by cheesecakegood on Tuesday August 18, 2026 @05:03PM (#49352675)
The library ‘ryp’[1] now exists that does the same, the data lives in an arrow format so you can write R inside Python without re-writing to disk

[1] https://github.com/briscverse/ryp

Re:Python Polars Cheatsheet (based on our O'Reilly book) by dajt on Wednesday August 19, 2026 @12:10AM (#49356684)
I use rpy2 for that. The scientists wrote the calc engine in R (via my Python transscription of the Excel original :) and I wrote the dashboard and data pipeline in Python. The data pipeline batch process embeds the R interpreter to avoid spawning processes all the time.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by mihaelm on Tuesday August 18, 2026 @10:37AM (#49346271)
The bare R experience is not that great, to put it mildly, but it's a whole other story if you add tidyverse on top of it. The data work becomes really easy then, but I still prefer Python because of familiarity and a better experience & ecosystem when you want to do anything beyond data wrangling & analysis.

I found `polars` to be a better experience than `pandas` even though I'd say it leaks some "Rustisms" in its Python APIs. But LLMs alleviate those pains and it's easy enough to review. I'd say it's even easier when there's less of a chance of implicit behavior.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by latent-person on Tuesday August 18, 2026 @03:57PM (#49351753)
> The bare R experience is not that great

Why do you say that? Base R is arguably nicer to work with data than pandas is for example. Happy to provide specific examples to prove my point if you want.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by lowmagnet on Tuesday August 18, 2026 @05:43PM (#49353123)
my main frustration with pandas was certain idioms did not work efficiently because they escaped the pandas kernel, causing memory copy and other bad behavior.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by qsort on Tuesday August 18, 2026 @10:45AM (#49346385)
If your work is more focused on statistics or pure modeling, then I agree R wins hands down. The issue is that most projects have "unclean" parts where you have to gather data from multiple sources, use connectors for services, S3 buckets and whatnot; dealing with that mess is where Python really shines.

AI probably changes the equation to some extent, but I still believe I'd rather maintain a complicated data pipeline like that in Python rather than R.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by jordansgoodman on Tuesday August 18, 2026 @10:55AM (#49346546)
Agreed. If the R community developed more data pipeline frameworks, following the "tidyverse" way of doing things, R would be my go to choice for all data related work.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by epihelix on Tuesday August 18, 2026 @11:42AM (#49347389)
Data science is a broad church, but my own branch of it (molecular biology, genomics and epigenetics, bioinformatics) and my partner's (ecology) are still very much R-based and entrenched. If you primarily care about statistical modeling, then R still wins (easily).
Re:Python Polars Cheatsheet (based on our O'Reilly book) by Vaslo on Tuesday August 18, 2026 @12:07PM (#49347842)
That doesn’t justify lots of stuff that R lacks vs Python. Anytime someone new joins my corp, they reluctantly move off of R from their academic days on Python and once in the ecosystem, they never look back
Re:Python Polars Cheatsheet (based on our O'Reilly book) by wsowens on Tuesday August 18, 2026 @12:34PM (#49348260)
Despite writing most of my procedural code in Python, I've always preferred doing my data analysis in R. For all of R's warts, the ergonomics of the dplyr + ggplot + the rest of the tidyverse are very tough to beat. My few attempts to use Pandas and matplotlib/seaborne have always proved frustrating. Based on this cheatsheet though, it seems like Polars addresses some of the friction of Pandas. Looking forward to trying it!
Re:Python Polars Cheatsheet (based on our O'Reilly book) by holub008 on Tuesday August 18, 2026 @04:00PM (#49351796)
Agreed, as an R and polars user. The fundamental advantage R holds over other languages/libraries is expressions. The ability to reference columns directly AND interoperate with vectorized base ops in R is unfair. Of course, this super power is equally confusing to learners, fraught for production code, etc.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by rtpg on Wednesday August 19, 2026 @01:14AM (#49357134)
do you have a snippet of what this looks like in R?
Re:Python Polars Cheatsheet (based on our O'Reilly book) by latent-person on Wednesday August 19, 2026 @01:49AM (#49357388)
Not OP, but here is an example using tidyverse (I leave the meaning of it to you; should be clear without any R knowledge):

  purchases |>
    group_by(country) |>
    filter(amount <= median(amount) * 10) |>
    summarize(total = sum(amount - discount))
Re:Python Polars Cheatsheet (based on our O'Reilly book) by 220hertz on Tuesday August 18, 2026 @01:59PM (#49349755)
Less friction, considerably faster. I have a statistician friend who's recently made the jump away from R. I think he would agree with you.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by mrtimo on Tuesday August 18, 2026 @01:40PM (#49349422)
I've moved from python/polars/pandas to DuckDB and have not looked back
Re:Python Polars Cheatsheet (based on our O'Reilly book) by sirfz on Tuesday August 18, 2026 @03:57PM (#49351757)
Yep, and chdb as well. Said this before, chdb's DatStore is a pretty neat pandas replacement too.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by viccis on Tuesday August 18, 2026 @02:56PM (#49350797)
Same. Almost every time I would use its streaming interfaces in Python, it would STILL materialize everything into memory. That was like 6 months ago. Maybe streaming interfaces actually work, but I found them to be leaky abstractions that required a ton of hand holding to make sure they didn't build a bunch of memory pressure, if you're lucky enough to even have a way to do it.

For example, last time I used it, you couldn't do NDJSON streaming scans from S3 (looks like fixed with PR #26563).

Re:Python Polars Cheatsheet (based on our O'Reilly book) by ismailmaj on Tuesday August 18, 2026 @01:43PM (#49349474)
even for just in-memory quick data analysis?
Re:Python Polars Cheatsheet (based on our O'Reilly book) by krapht on Tuesday August 18, 2026 @02:22PM (#49350145)
spinning up a venv with duckdb: 5 minutes

using sql everywhere; never having to remember dataframe syntax: timeless

Re:Python Polars Cheatsheet (based on our O'Reilly book) by rtpg on Wednesday August 19, 2026 @01:15AM (#49357149)
what is the visualisation strategy here? I find post-hoc grouping and plotting in pandas pretty satisfying.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by mrtimo on Saturday August 22, 2026 @12:29AM (#49396570)
Check out malloyyo on github
Re:Python Polars Cheatsheet (based on our O'Reilly book) by nojito on Tuesday August 18, 2026 @07:30PM (#49354402)
Re:Python Polars Cheatsheet (based on our O'Reilly book) by paulfharrison on Tuesday August 18, 2026 @04:15PM (#49352015)
I'm sure Polars is great, but I can't get over needing 10 characters of ceremony every time I want to refer to a column in a data frame.

pl.col("...")

Re:Python Polars Cheatsheet (based on our O'Reilly book) by thijsn on Tuesday August 18, 2026 @04:44PM (#49352436)
I've seen people with exactly that frustration use "import polars.col as c" and use c("colname") instead!
Re:Python Polars Cheatsheet (based on our O'Reilly book) by laGrenouille on Tuesday August 18, 2026 @06:21PM (#49353600)
Yes, this (as the even shorter c.colname) and the fact that you can do var= in place of assign in with_columns/agg changed my whole outlook on polars. Have been using it as my main driver for the past year.
Re:Python Polars Cheatsheet (based on our O'Reilly book) by mmplxx on Tuesday August 18, 2026 @06:21PM (#49353601)
Or c.colname
Re:Python Polars Cheatsheet (based on our O'Reilly book) by vovavili on Tuesday August 18, 2026 @05:12PM (#49352780)
Every time:

   import polars as pl
   
   from polars import col, lit
Re:Python Polars Cheatsheet (based on our O'Reilly book) by ForceBru on Tuesday August 18, 2026 @06:16PM (#49353544)
Sure, but these ten characters let you treat columns as values and do math on them, which is super intuitive, in my opinion. I've been using Pandas for quite some time and always kinda sucked at it. One day I decided to give this new library Polars a try. Now I can do things I couldn't even dream of with Pandas! And it's fast, too!

I think of `pl.col` as delayed evaluation: I want to do math on the vector of values of this column. But wait, let me just refer to the name of that column and build the expression that I want to compute. Then I hand this expression to Polars and it retrieves the actual values of the columns my expression refers to and executes the operations.

IMO, it would've been great to just do math on strings, like `"Amount" * "Price" - "Losses"`, but programming languages either don't allow math on strings or that math is actually string concatenation, which is not what we want. So we have to wrap the name of the column into some object. This is just an API thing.

As a side note, it's such a pity that there's basically no Polars for the Julia language! There is some wrapper package, but it seems old and unmaintained. I can't seem to properly learn DataFrames.jl for some reason, I always miss Polars when I use Julia.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by mmplxx on Tuesday August 18, 2026 @06:20PM (#49353593)
c = pl.col

c.foo + c.bar

Re:Python Polars Cheatsheet (based on our O'Reilly book) by paulfharrison on Tuesday August 18, 2026 @10:06PM (#49355664)
Nice. This is close enough to an R level of brevity, without any R dark magic.

Would be a great addition to the cheatsheet.

Re:Python Polars Cheatsheet (based on our O'Reilly book) by brikym on Tuesday August 18, 2026 @04:30PM (#49352246)
echo "Never use pandas, use polars instead" >> AGENTS.md
Re:Python Polars Cheatsheet (based on our O'Reilly book) by kirubakaran on Tuesday August 18, 2026 @05:44PM (#49353136)
>> unless you want that line to be the only thing in your AGENTS.md
Re:Python Polars Cheatsheet (based on our O'Reilly book) by dalemhurley on Tuesday August 18, 2026 @04:58PM (#49352619)
Why do Python users use acronyms instead of verbose variable names?
Re:Python Polars Cheatsheet (based on our O'Reilly book) by rtpg on Wednesday August 19, 2026 @01:13AM (#49357129)
Pandas and Polars are both a place where I _really_ would love to have some sort of macro subsystem for Python. `pl.col(...)` is a neat trick for slicing, the pandas `df[df["foo"] == "bar"]` thing has always felt a bit of a mouthful (especially if you deign to use a longer name for your dataframe).

I appreciate Polars offering some alternative APIs for poking around in data, though. I feel like at some point someone will land on a _very_ nice to use API