简体   繁体   中英

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

The above dataframe, as well as other dataframes need to have the reviews converted from multiple languages to English. Through looking online I was told to use the following code:

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)

However, this presented me with the following error:

HTTPError: HTTP Error 429: Too Many Requests

Through looking online I have seen that sleep time can change this, but I have been able to change it and think it's unlikely that the method will work. Does anyone have a fix to this? Thanks.

It only allows about 100 requests per one hour period and there after returns a 429 error (Too many requests). On the other hand, the Google Translate Api has a default billable limit of 5 requests/second/user and 200,000 requests/day."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM