Skip to content

Instantly share code, notes, and snippets.

@AlexDel
Created December 12, 2019 10:56
Show Gist options
  • Save AlexDel/0566702702b725bd8bc811dd7b887ea9 to your computer and use it in GitHub Desktop.
Save AlexDel/0566702702b725bd8bc811dd7b887ea9 to your computer and use it in GitHub Desktop.
def calc_tokens_feature(targetTokens=[]):
def calc_tokens_ratio(textTokens=[]):
counter = 0
if len(textTokens) == 0:
return 0
for token in textTokens:
if token in targetTokens:
counter +=1
# возвращаем не данные а функцию, которую можно вызвать в apply.
return calc_tokens_ratio
calc_death_ratio = calc_tokens_feature(['смерть', "умереть", "похороны"])
vkDataFrame['death_ratio'] = vkDataFrame['normal_tokens'].apply(calc_death_ratio)
# или можно так еще
vkDataFrame['death_ratio'] = vkDataFrame['normal_tokens'].apply(calc_tokens_feature(['смерть', "умереть", "похороны"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment