TextBlob转换器无法检测到datafram中的不同语言

2024-10-02 00:39:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用TextBlob运行语言转换器。它可以从字符串翻译过来。但是,我尝试为数据帧中的数据循环textblob转换器,而数据帧中的数据可能混合了不同的语言(en和es)。你知道吗

我使用的代码是:

for content in data:
  blob = TextBlob(content)

for i in data:
  blob = TextBlob(i)

blob.translate(from_lang = 'en', to = 'es')

错误是:

    83             result = result.encode('utf-8')
    84         if result.strip() == source.strip():
---> 85             raise NotTranslated('Translation API returned the input string unchanged.')
    86 
    87     def _request(self, url, host=None, type_=None, data=None):

NotTranslated: Translation API returned the input string unchanged.

Tags: 数据innone语言fordataesresult
1条回答
网友
1楼 · 发布于 2024-10-02 00:39:30

因为没有必要在每种情况下“en”和“es”必须不同。在许多情况下,“es”和“en”具有相同的文本。所以在两者相同的情况下会出现错误。使用try-and-catch语句将处理所有具有相同文本的情况,最终使代码正常工作。你知道吗

for content in data:
  blob = TextBlob(content)

for i in data:
  blob = TextBlob(i)
  try:
     print (blob.translate(from_lang = 'en', to = 'es'))
  except:
     print ("Same translation so skipping")


相关问题 更多 >

    热门问题