I'm trying to translate the values of certain dataframe rows. The criteria is the language of the value. the column contains both English and French text. I want to translate the English text to French.
Here's what I'm currently doing
# Define a function to translate English to French using Google Translate API
def translate_english_to_french(text):
from googletrans import Translator
translator = Translator()
return translator.translate(text, src='en', dest='fr').text
# Translate the English text to French if the language is English
df.loc[df['language'].apply(lambda x: x['language']) == 'en', 'all_activities'] = df.loc[df['language'].apply(lambda x: x['language']) == 'en', 'all_activities'].apply(translate_english_to_french)
Problem is I'm getting this error
AttributeError: 'NoneType' object has no attribute 'group'
The language column contains values in this format:
{'language': 'en', 'score': 0.9999966639250509}