[英]Translating comments using google translate api python
我正在嘗試將馬來語評論翻譯成英語。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import re
from bs4 import BeautifulSoup
from nltk.stem.porter import PorterStemmer
from nltk.corpus import stopwords
from wordcloud import WordCloud, STOPWORDS
from sklearn.feature_extraction.text import CountVectorizer
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
%matplotlib inline
reviews = pd.read_csv("/SentimentAnalysis/PROJECT_SENTIMENTANALYSIS/shopee_review.csv")
# There are 2943 duplicates
reviews[reviews.duplicated(['comment'])].shape
# Drop duplicates as we only want unique reviews
reviews.drop_duplicates(['comment'], inplace=True)
# Reindex the dataframe
reviews.reset_index(drop=True, inplace=True)
from googletrans import Translator
def translatee(txt):
translation = translator.translate(txt, dest="en")
return translation
reviews['tranlated']=reviews['comment'].map(translatee).text
但我收到錯誤: AttributeError: 'NoneType' object has no attribute 'group'
。 下面附上截圖。
需要一些幫助,謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.