course content

Course Content

Data Manipulation using pandas

Manipulating StringsManipulating Strings

If you want to replace specific symbol in string, you need to apply the .replace() method, passing the element you want to replace as the first parameter, and the element that should take its place as the second parameter. For instance,

As you can see, the comma was replaced by the dot symbol. But how to perform replacements for the whole column? On one side, we can run loop, and perform a replacement for every element. But it's very irrational.

pandas allows you to apply string methods to the whole column within one action. To do it, you need to set the str accessor to column, and then specify the method you want to perform. For instance, we can replace the - symbols in the address column with underscore _ characters.

And finally, you need to convert modified values into new type. pandas also allows us to perform that within one action by applying the .astype() method. The parameter of the method should be the type you want to convert to (int, float, str, etc.).

Section 1.

Chapter 4