by aorist · 3y ago · 0 comments
Compare:
pd_df.groupby(['date'])['failure'].count() # pandas
pl_df.groupby(pl.col('date')).agg(pl.count('failure')) # polars
dt[, .N, date] # R data.table
In both Pandas and Polars, the specification of the date has to be a string inside a list or method call, but in R it can be a bare token.R is not a replacement for pandas.
R is it’s own special little painful ecosystem, loved by people who don’t have to maintain the code they write.
You can complain all you like about pandas, but at the end of the day, it’s python. Python tooling works with it. The python ecosystem works with it.
It’s not without faults, but at least you’ll have a community of people to help when things go wrong.
R, not so much.
(Spoken as jaded developer who had to support r on databricks, which is deep in the hell of “well, it’s not really a tier one language” even from their support team)
Sounds like you worked with (or wrote) really bad R code.
…the point I’m making is that when you already have bad r code, it’s a massive pain in the ass.
Bad python is terrible too, but lots of people know python, and it’s easy to find help to unduck bad python code and turn it into maintainable code.
That has not been my experience with r. Ever. At any organisation.
Your experience may vary. (:
Do you think it’s because R code tends to be written by statisticians and stats-adjacent domain experts who don’t necessarily know how to write clean code while Python code has at least some input from actual programmers? Or is this really down to the language itself?
Maybe I'm just jaded because I've inherited a 100K+ line R codebase at my job written by a single person with no unit tests and about 3 lines of comments, and it's a completely miserable experience.
dplyr syntax IMO is the best balance between clarity and nonredundancy as evident in pandas/polar code.
e.g.
> iris.groupby('species').count()
sepal_length sepal_width petal_length petal_width
species
setosa 50 50 50 50
versicolor 50 50 50 50
virginica 50 50 50 50
vs. > iris.groupby('species')['sepal_length'].count()
species
setosa 50
versicolor 50
virginica 50R is also impossible to understand whta is actually going on.
``` pd_df['date'].value_counts() # pandas pl_df.select(pl.col('date').value_counts()) # polars ```
Note: we could also do it the Pandas way in Polars but square bracket indexing in Polars is not recommended