【问题标题】:How do I translate dataframe column with multiple languages to English without getting: HTTP Error 429: Too Many Requests如何将具有多种语言的数据框列翻译成英语而不得到:HTTP 错误 429:请求过多
【发布时间】:2020-11-17 03:30:33
【问题描述】:
 Unnamed: 0  rating                                             review
0              0       4  Biggest disappointement ever. It was supposed ...
1              1       4  Destiny is not innovative. This game was alrea...
2              2       2  I was able to play the beta with a couple frie...
3              3       4  I liked the intro, sadly it was all downhill f...
4              4       2  Embrace yourself for Activision $500 million w...
...          ...     ...                                                ...
1765        1765       2  It tried so hard and it got so far. Destiny is...
1766        1766       4  Extremely over hyped. It left me feeling meh. ...
1767        1767       5  The positive reviews here are basically trying...
1768        1768       6  You can absolutely tell that this game is from...
1769        1769       0  Woulda gave this an honest 5, but Bungie score...

上述数据框以及其他数据框需要将评论从多种语言转换为英文。通过在线查找,我被告知使用以下代码:

from time import sleep
from textblob import TextBlob
from textblob.exceptions import NotTranslated    

def translate_comment(x):
    try:
        # Try to translate the string version of the comment
        return TextBlob(str(x)).translate(to='en')
    except NotTranslated:
        # If the output is the same as the input just return the TextBlob version of the input
        return TextBlob(str(x))

for i in range(len(df2['review'])):
    # Translate one comment at a time
    df2['review'].iloc[i] = translate_comment(df2['review'].iloc[i])

    # Sleep for a quarter of second
    sleep(0.25)

但是,这给我带来了以下错误:

HTTPError: HTTP Error 429: Too Many Requests

通过在线查看,我发现睡眠时间可以改变这一点,但我已经能够改变它,并认为该方法不太可能奏效。有没有人可以解决这个问题?谢谢。

【问题讨论】:

    标签: python dataframe google-colaboratory google-translate textblob


    【解决方案1】:

    它在一小时内只允许大约 100 个请求,然后返回 429 错误(请求太多)。另一方面,Google Translate Api 的默认计费限制为 5 个请求/秒/用户和 200,000 个请求/天。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      相关资源
      最近更新 更多