Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Data Analysis Cleaning and Preparing Data Selecting Relevant Data Choosing the Right Features

Clean demo data

Hi, For those who need to clean their demographic data. You can simply copy and run the following code after uploading the file :

demo.loc[:,'DMDEDUC3'] = demo.loc[:,'DMDEDUC3'].str.strip()
replace_dict = {'DMDEDUC3': {
                            "Never Attended / Kindergarten Only":0, 
                            "1st Grade":1,
                            "2nd Grade":2,
                            "3rd Grade":3,
                            "4th Grade":4,
                            "5th Grade":5,
                            "6th Grade":6,
                            "7th Grade":7,
                            "8th Grade":8,
                            "9th Grade":9,
                            "10th Grade":10,
                            "11th Grade":11,
                            "12th Grade":12,
                            "High School Graduate":13,
                            "GED or Equivalent":14,
                            "More than high school":15,
                            "Less Than 5th Grade":55,
                            "Less Than 9th Grade":66,
                            "Don't know":99,
                            "12th Grade, No Diploma":12
demo.replace(replace_dict, inplace=True)

demo.loc[:,'DMDEDUC2'] = demo.loc[:,'DMDEDUC2'].str.strip()
replace_dict = {'DMDEDUC2': { 
                            "Less Than 9th Grade":1,
                            "9-11th Grade (Includes 12th grade with no diploma)":2,
                            "High School Grad/GED or Equivalent":3,
                            "Some College or AA degree":4,
                            "College Graduate or above":5,
                            "Don't Know":9,
demo.replace(replace_dict, inplace=True)

1 Answer

Linda Shum
Linda Shum
12,609 Points

So helpful! Thanks Jason.