Skip to content

Instantly share code, notes, and snippets.

@cereniyim
Created April 29, 2020 11:54
Show Gist options
  • Save cereniyim/05fa76649637e71832dc34c78d367c25 to your computer and use it in GitHub Desktop.
Save cereniyim/05fa76649637e71832dc34c78d367c25 to your computer and use it in GitHub Desktop.
year extraction function from feature
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