【发布时间】: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