course content

Course Content

Data Manipulation using pandas

Replacing Specific ElementsReplacing Specific Elements

The next step we need to do is to replace dots. This task is a bit harder than the previous one, since you will replace only specific elements.

First, let's remind how to select specific rows and columns based on some condition. It can be done by applying the .loc[] property. The first parameter is either row numbersm, or condition; the second one is column names. For instance, let's get the rows containing only dot characters . within the 'morgh' column.

Since we accessed the necessary rows, we can easily replace them by reassigning. We are going to repalce all the dots by NA values (nan from NumPy) and then convert the resulting column to float type (NA doesn't support int type, float only).

As you can see, the column is now considered to have float type, which means you can apply numerical methods to it (i.e., you can calculate mean, min, max, etc.).

Everything was clear?

Section 1. Chapter 6