Iterating Over Rows in Pandas

Ben Cook • Posted 2021-01-29 • Last updated 2021-10-15

When you absolutely have to iterate over rows in a Pandas DataFrame, use the .itertuples() method.

Installing Packages in a Jupyter Notebook

Ben Cook • Posted 2021-01-22 • Last updated 2021-10-15

This post describes a trick for installing/upgrading Python packages in a Jupyter notebook. It’s useful for scratch code, but don’t do this when you need reproducible code.

Normalizing Images in PyTorch

Ben Cook • Posted 2021-01-15 • Last updated 2021-10-21
normalized cat image pytorch

You can use the torchvision Normalize() transform to subtract the mean and divide by the standard deviation for image tensors in PyTorch. But it’s important to understand how the transform works and how to reverse it.

Dropping Columns and Rows in Pandas

Ben Cook • Posted 2021-01-14 • Last updated 2021-10-15

There are a few ways to drop columns and rows in Pandas. This post describes the easiest way to do it and provides a few alternatives that can sometimes be useful.

NumPy Norm: Understanding np.linalg.norm()

Ben Cook • Posted 2021-01-08 • Last updated 2021-10-15

You can calculate the L1 and L2 norms of a vector or the Frobenius norm of a matrix in NumPy with np.linalg.norm(). This post explains the API and gives a few concrete usage examples.