From the course: Data Cleaning in Python Essential Training

Unlock this course with a free trial

Join today to access over 25,400 courses taught by industry experts.

Fixing types

Fixing types

- Such formats, such as CSV, do not have type information. When pandas loads the data, it will guess what are the data types, but sometimes we need to give it some extra help. Let's have a look at some data about points and their colors. So, here's our CSV, we have X and Y, which are the coordinates, and then the color, and is it visible or not. And here is our code. Let's start by loading the data frame and showing the data types. And I'm going to hide the bar on the left. And we see that the points X and Y are int 64. The color and the visible are object, which means a string. Let's fix the color first. So I'm defining function asint, which uses the built-in int function on the value and says base equal zero, meaning get the base from the string itself. Since our data has zero X at the beginning, it is going to use base 16. And if you run it now, we see now that…

Contents