Created
August 28, 2021 17:40
-
-
Save marcosan93/34bd65053a2e6126629672f17695a4cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getEducation(dob): | |
| """ | |
| Assigns an education level based on the given date of birth | |
| """ | |
| # Current date | |
| now = datetime.datetime.now() | |
| # Date of birth | |
| dob = datetime.datetime.strptime(dob, "%Y-%m-%d") | |
| # Subtracting the times to get an age | |
| age = int((now - dob).days/365.25) | |
| # Returning education level based on age | |
| if age <= 18: | |
| return 'high school' | |
| elif age <= 22: | |
| return 'undergrad' | |
| elif age <= 25: | |
| return 'grad' | |
| else: | |
| return 'employed' | |
| df['education'] = [getEducation(i) for i in df['dob']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment