Skip to content
datarekha

Python

12 articles in this topic.

Python Aug 15, 2026

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.

11 min read Read
Python Jun 2, 2026

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.

9 min read Read
Python Jun 2, 2026

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.

9 min read Read
Python Jun 2, 2026

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.

8 min read Read
Python Jun 2, 2026

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.

10 min read Read
Python Jun 2, 2026

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.

9 min read Read
Python Jun 2, 2026

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.

10 min read Read
Python Jun 2, 2026

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.

8 min read Read
Python Jun 2, 2026

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.

10 min read Read
Python Jun 2, 2026

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.

8 min read Read
Python Jun 2, 2026

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.

9 min read Read
Python Jun 2, 2026

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.

9 min read Read