在标记化我的";脚本";柱但是我得到一个AttributeError。我尝试了不同的
这是我的";脚本";列:
df_toklem["script"][0:5]
---------------------------------------------------------------------------
type(df_toklem["script"])
输出:
id
1 [ext, street, day, ups, man, big, pot, belly, ...
2 [credits, still, life, tableaus, lawford, n, h...
3 [fade, ext, convent, day, whispering, nuns, pr...
4 [fade, int, c, hercules, turbo, prop, night, e...
5 [open, theme, jaws, plane, busts, clouds, like...
Name: script, dtype: object
---------------------------------------------------------------------------
pandas.core.series.Series
以及我尝试应用引理的代码:
from textblob import Word
nltk.download("wordnet")
df_toklem["script"].apply(lambda x: " ".join([Word(word).lemmatize() for word in x.split()]))
错误:
[nltk_data] Downloading package wordnet to
[nltk_data] C:UsersPCAppDataRoamingnltk_data...
[nltk_data] Package wordnet is already up-to-date!
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-72-dbc80c619ec5> in <module>
1 from textblob import Word
2 nltk.download("wordnet")
----> 3 df_toklem["script"].apply(lambda x: " ".join([Word(word).lemmatize() for word in x.split()]))
~Anaconda3libsite-packagespandascoreseries.py in apply(self, func, convert_dtype, args, **kwds)
4198 else:
4199 values = self.astype(object)._values
-> 4200 mapped = lib.map_infer(values, f, convert=convert_dtype)
4201
4202 if len(mapped) and isinstance(mapped[0], Series):
pandas_libslib.pyx in pandas._libs.lib.map_infer()
<ipython-input-72-dbc80c619ec5> in <lambda>(x)
1 from textblob import Word
2 nltk.download("wordnet")
----> 3 df_toklem["script"].apply(lambda x: " ".join([Word(word).lemmatize() for word in x.split()]))
AttributeError: 'WordList' object has no attribute 'split'
我尝试了不同的方法,但不幸的是找不到有效的解决方案。谢谢你抽出时间。
您尝试执行的操作将不起作用,因为您正在将字符串函数(split(应用于单词列表。我会尝试使用nltk
,并用我的标记化数据创建一个新的panda列:
import nltk
df_toklem['tokenized'] = df_toklem.apply(lambda row: nltk.word_tokenize(row['script']))