course content

Course Content

Data Manipulation using pandas

Simultaneous ReplacementSimultaneous Replacement

The method described in the previous chapter allows you to replace specific values in one column 'manually'. But we need to perform replacements in 4 columns, which means we need to repeat the actions at least 3 more times.

However, pandas predicted that task, too. Let's consider the method that allows to perform replacement for all dataframe columns.

Explanation: condition is the first parameter, if True, then keeps original values, if False, then replaces them by values specified in the other parameter. inplace - if True, then rewrites the data. If you want to 'revert' the condition to opposite, place the ~ symbol in front of it. For instance, let's replace all the zeros with the word null.

As you can see, there are many 'null's appeared in the dataframe. If you remove the ~ symbol within the .where() method, then all values but 0 will be replaced to 'null'.

Section 1.

Chapter 7