This article is part of a series of practical guides for using the Python data processing library pandas. To see view all the available parts, click here.

In this guide we are going to look at three ways to handle a scenario where you want to update the values in a column based on whether some condition is true or not. This condition could be applied based on the same column you want to update, a different column, or a combination of columns.

The three methods (or two methods and a function we will look at are:

  1. where – a method of the pandas.DataFrame class.
  2. mask – a method of the pandas.DataFrame class and inverse of where
  3. numpy.where – a function in the numpy library.
Continue reading