Skip to content

Instantly share code, notes, and snippets.

@cereniyim
Last active April 29, 2020 13:47
Show Gist options
  • Save cereniyim/fb5d8fd9afbf075c79890a7fd0066b40 to your computer and use it in GitHub Desktop.
Save cereniyim/fb5d8fd9afbf075c79890a7fd0066b40 to your computer and use it in GitHub Desktop.
extract features function
def ExtractFeatures(df):
# adds is_red, is_white, is_rose, is_rose
# is_sparkling, is_dry, is_sweet
for key, value in desc_extracting_dict.items():
interim_df = extract_features_from_description(df, "description", key, value)
# adds year
interim_df["title_numlist"] = (interim_df
.title
.str
.findall(r'\b\d+\b'))
interim_df["year"] = (interim_df
.title_numlist
.apply(extract_year_from_title))
# adds is_blend
interim_df["is_blend"] = (interim_df
.variety
.apply(extract_blend_from_variety))
# drops unused features
features_added_df = (interim_df
.drop(columns=["description",
"title",
"title_numlist"]))
return features_added_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment