Issue
I am working on a Pandas dataframe in which users' occupations are defined with numbers.
This is how my data looks like
according to the metadata, the numbers are chosen from the following list:
* 0: "other" or not specified
* 1: "academic/educator"
* 2: "artist"
* 3: "clerical/admin"
* 4: "college/grad student"
* 5: "customer service"
* 6: "doctor/health care"
* 7: "executive/managerial"
* 8: "farmer"
* 9: "homemaker"
* 10: "K-12 student"
* 11: "lawyer"
* 12: "programmer"
* 13: "retired"
* 14: "sales/marketing"
* 15: "scientist"
* 16: "self-employed"
* 17: "technician/engineer"
* 18: "tradesman/craftsman"
* 19: "unemployed"
* 20: "writer"
I need to replace these numbers with the right occupation titles.
I have already created the following dictionary, But I don't know what is the best way to replace the values.
I appreciate your help :)
occupation={0:"other or not specified", 1:"academic/educator", 2:"artist", 3:"clerical/admin", 4:"college/grad student", 5:"customer service", 6:"doctor/health care", 7:"executive/managerial" , 8:"farmer", 9:"homemaker",10:"K-12 student", 11:"lawyer", 12:"programmer", 13:"retired", 14:"sales/marketing", 15:"scientist", 16:"self-employed", 17:"technician/engineer",18:"tradesman/craftsman", 19:"unemployed",20:"writer"}
Solution
This can be achieved using pandas.Series.map, as follows:
df['occupation'].map(occupation)
Answered By - vtasca
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.