簡體   English   中英

如何將具有多種語言的 dataframe 列翻譯成英語而不得到:HTTP 錯誤 429:請求過多

[英]How do I translate dataframe column with multiple languages to English without getting: HTTP Error 429: Too Many Requests

 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...

上述 dataframe 以及其他數據框需要將評論從多語言轉換為英文。 通過在線查看,我被告知使用以下代碼:

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

通過在線查看,我看到睡眠時間可以改變這一點,但我已經能夠改變它並且認為該方法不太可能奏效。 有沒有人可以解決這個問題? 謝謝。

它在一小時內只允許大約 100 個請求,然后返回 429 錯誤(請求太多)。 另一方面,谷歌翻譯 Api 的默認計費限制為 5 個請求/秒/用戶和 200,000 個請求/天。”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM