[Music] changing misleading field values the field days underscore since previous is a count of numbers of days since the client was last contacted from the previous campaign this field is clearly numeric so we can look at a histogram of days underscore since underscore previews not that most of the data values are near 1000 with a minority of values near zero it turns out that the database administrator used the code 999 to represent customers who had not been contacted previously thus we need to change the field value 999 to missing which is done as follows in
phyton if you did not open the panda package or read in the dataset as described in the previous phyton section you have to do it now we will use import numpy as np this is to identify all new records which days underscore since underscore previews value of 999 and replace them with the python code for missing numbers n a n once the replacement is made we will save the variable under this underscore since underscore previous variable name effectively overriding the previous variable's value we will use train underscore train bracket this underscore since underscore previews close
bracket remember to always put single code equals bank underscore train open bracket these underscore scenes underscore previews that replace open parenthesis curly bracket 999 colon mp.nan close curly bracket and close parenthesis the command replace open parenthesis open curly bracket 999 colon mp.nan close curly bracket close parenthesis finds each instance of 999 in the days underscore since previous variable and replaces it with the value nan to create a histogram of the variable use the hist command bump underscore train open bracket base underscore scenes underscore previews close bracket dot plot open parenthesis kind equal to his then
title equals to histogram of days since previews then close parenthesis using that plot command after the variable name will make a plot of the variable we use kind equals hist to specify that a histogram should be made the title input contained in a single quotes creates the title of the histogram note that the field is categorical meaning that there is no ordering of field values in other words if we left the field as it is then our data science algorithms would not know that university under degree represents more education than basic that for here to
provide this information to our algorithms we transform the data values into numeric values where it is clear that one value is larger than another one needs to proceed with care when doing this so that the relative differences among the various categories are preserved we will replicate the education variable and name it education underscore numeric in preparation for replacing its categorical values with numeric ones you may refer the syntax written in the slide the right hand side of the equal sign specifies the education variable and the equal sign assigns those values to the left hand side
there are currently no variable name education underscore numeric so one will be created and given the values of that variable education we need to set up a dictionary specifically for converting the categorical values in education underscore numeric variable to numeric values the dictionary is contained in curly brackets to set up the dictionary as follows you may refer to the command or syntax written in the slide inside the dictionary we use education underscore numeric to specify the variable which we want to record followed by a colon in another set of curly brackets within this second set
of curly brackets we specify the recording in the following order variables original value colon variables new value each specification is separated by a comma note that we use phyton's value for missing numeric values nan where necessary then finally we tell phyton to use the dictionary to replace the variable values you may refer to this command the command replace will replace the values according to the rules in the dictionary dick underscore edu [Music] you