I am trying to translate malay comments to english.
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
but i'm getting the error: AttributeError: 'NoneType' object has no attribute 'group'
. Screenshot attached below.
Will need some help, thank you
I don't see any
translator = Translator()
in your code. It would be one of the reason. See an example with googletrans below which works without an issue.Here is the code's answer: