Loading tutorials
timeit is. You will learn a repeatable way to check that a vectorised rewrite is correct and faster. Do both checks before you replace any loop in real code.2 min readdf["price"] * df["qty"] works on whole columns, which the previous chapter covered.2 min readif/elif/else in Python, build a DataFrame, and use boolean masks like df["qty"] >= 3. It shows how to replace branching inside a row loop with one expression per column.3 min readgroupby at a basic level. The goal is to replace loops over groups, and loops that look up each row's group total, with one vectorised expression.2 min readgroupby, and write column arithmetic. It covers logic that looks like it needs a loop because each row depends on the row before it. Three methods handle most of these cases: shift, diff and the cumulative family.2 min readmap and merge do it for the whole column at once.2 min readtimeit. It compares the three common ways to run Python code once per row, so you can judge when each is acceptable.2 min readdf.dtypes, and have seen column arithmetic and groupby in the earlier chapters.2 min readgroupby, and have timed a loop against a vectorised version with timeit. It covers how to recognise code that cannot be vectorised, and what to do when you reach one.3 min read