Created
April 29, 2020 11:54
-
-
Save cereniyim/05fa76649637e71832dc34c78d367c25 to your computer and use it in GitHub Desktop.
year extraction function from feature
This file contains 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 extract_year_from_title(title): | |
# function to find the year in the given list | |
# if not found assigns zero as year | |
# ASSUMPTION: There is no NA values | |
# in the title feature | |
int_list = [] | |
now = datetime.datetime.now() | |
for item in title: | |
int_list.append(int(item)) | |
for item in int_list: | |
if item <= now.year and item >= 1900: | |
return item | |
else: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment