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:
where– a method of the pandas.DataFrame class.
mask– a method of the pandas.DataFrame class and inverse of
numpy.where– a function in the numpy library.