![](/img/trans.png)
[英]How do I singularize and lemmatize an entire pandas dataframe column using TextBlob?
[英]Lemmatize using Textblob in python
我已經編寫了使用文本blob在Python中使句子定理的代碼,但沒有得到預期的結果:
def get_lemmatize_text(transcript):
transcript = transcript.strip()
blob = TextBlob(transcript)
for word in blob:
expected_str = Word(word)
expected_str = expected_str.lemmatize()
return expected_str
print(get_lemmatize_text("he had not received the four letters we d sent him as he had been travelling for the whole of august and hadn t received any call or text from us . he has just arrived today and has called us straight away . he has also just of his account when he had asked for it to be cancelled before it switched from the first additions datestr . he says he received contact from us that we were looking into this but doesnot have that to hand"))
我得到以下輸出: d
出了什么問題? 誰能幫助我或糾正我?
您的代碼將句子作為字符明智的.split()
迭代將解決該問題。 那么您就不會保留您的結果,這就是為什么要獲取上一個迭代list
追加的結果會解決這一問題的原因。 如果您解決了這兩個問題,您的代碼將可以正常工作:)嘗試執行此操作,
blob = TextBlob(transcript).split()
result=[]
for word in blob:
expected_str = Word(word)
expected_str = expected_str.lemmatize()
result.append(expected_str)
return result #or try this return ' '.join(result)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.