Data Science Jumpstart with 10 Projects Transcripts
Chapter: Project 5: Cleaning Heart Disease Data in Pandas
Lecture: Converting the Numeric Sex Column into a String

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this section, I'm going to show you how to clean up the sex column. First of all, let's just look at the sex column.
0:06 You'll note that I am keeping that previous conversion from age in there. I'm going to build up a chain.
0:12 I'm going to pull off the sex column and then look at the value counts. Again, if you want to walk through this chain or recipe,
0:19 here's the original data frame. I'm converting age to an int8. That doesn't change anything visibly here. I'm going to plot the sex column.
0:27 This is ones and zeros. Let's just validate that and we see that it is ones and zeros.
0:32 What I want to do is I want to replace one with male and zero with female. Let's try and run that. When I do that, Arrow isn't very happy.
0:42 Arrow doesn't like to change the type under the covers for us. This would be going from an integer column to a string column.
0:49 Arrow's not very happy about that. Instead, what I'm going to do is I'm first going to change it to a string type
0:54 and then I'm going to replace those values with male and female. Let's run that and see if that works. It looks like it did work.
1:02 Let's just validate that by doing value counts and that looks like that worked. We showed how to convert the sex type.
1:09 We had to convert the numbers to strings and then we can convert the string versions of the numbers into the strings that we want them to be.


Talk Python's Mastodon Michael Kennedy's Mastodon