0

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}
Moe_blg
  • 71
  • 4
  • 1
    Hi, welcome to StackOverflow. Please take the [tour](https://stackoverflow.com/tour) and learn [How to Ask](https://stackoverflow.com/help/how-to-ask). In order to get help, you will need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If your question include a pandas dataframe, please provide a [reproducible pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – alec_djinn Mar 31 '23 at 12:40
  • Can you try reinstalling the latest version of the translate api ? – Nestor Ceniza Jr Apr 03 '23 at 14:01

0 Answers0