我有get_tags返回与文本对应的标签列表的函数:
def get_tags(text):
# Do some analysis and return a list of tags
return tags
Run Code Online (Sandbox Code Playgroud)
例如,get_tags(text1)返回['a', 'b', 'c']时get_tags(text2)返回['a', 'b']
我还有一个 Pandas DataFrame df,列[text, a, b, c, d, e, f]有 500,000 行。我想填充 1 作为特定行中文本的标签。现在,我正在执行
for i in range(len(df)):
df.loc[i, get_tags(df.loc[i, "text"])] = 1
Run Code Online (Sandbox Code Playgroud)
这是痛苦的缓慢。我可以使用,joblib但在此之前我想看看实现这一目标的最有效方法。
在执行之前, df看起来像这样:
text a b c d e f
0 text having a, b, c tags 0 0 0 0 0 0 …