Created
December 12, 2019 10:56
-
-
Save AlexDel/0566702702b725bd8bc811dd7b887ea9 to your computer and use it in GitHub Desktop.
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 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