Python
12 articles in this topic.
apply() is a for loop in disguise
Rewriting a Python loop as .apply() makes the code shorter and almost never makes it faster, because .apply() is the same loop with a nicer costume. Here is the ladder that does make it faster.
Broadcasting is the NumPy idea that takes a week to click
Broadcasting — NumPy's rule for combining arrays of different shapes by silently stretching size-1 dimensions — looks like magic until you see the geometry, and then you can never unsee it.
Categoricals: the Pandas dtype that pays for itself
A column of repeated country codes that looks like strings is silently eating ten times the memory it needs — and making every groupby slower than it has to be.
Decorators are just functions that wrap functions
The @ symbol is pure syntactic sugar for a pattern you already know: pass a function in, get a smarter function back.
Comprehensions, generators, and the art of not building the list
The gap between a list comprehension and a generator expression is just two characters, but at ten million rows it is the difference between a program that breathes and one that chokes.
Your Pandas merge silently 10x'd the rows — here's why
A join between two tables where the key is not unique on one side silently multiplies rows for every matching pair, and pandas will not warn you unless you tell it to.
Method chaining: writing pandas like a pipeline, not a pile
Chaining assign, query, groupby, and agg into one readable pipeline beats a pile of intermediate variables — it reads top to bottom like a recipe, kills stale-variable bugs, and sidesteps the SettingWithCopy trap.
The mutable default argument, and other Python footguns
Python evaluates default argument values exactly once, at function definition time, which means a mutable default is a shared object that silently accumulates state across every call.
SettingWithCopyWarning, finally explained
The most-Googled pandas warning is not about copying — it is about whether the memory you are writing to is the DataFrame you think it is.
The axis argument everyone gets backwards
Axis in NumPy and Pandas names the dimension you destroy, not the one you keep — and once that clicks, every aggregation you write becomes obvious.
Type hints are documentation that can't go stale
A docstring lies without consequence, but a type hint that disagrees with the code is caught by your editor before you even save the file.
Why Python is slow — and the times it actually matters
A tight Python loop over a million numbers can be 100x slower than C, but that rarely matters — until it suddenly, catastrophically does.