Can I make an apply of a function to a dataframe column by filtering rows with another column value?
My actual code is:
df['description_text_clean'] = df.description_text_clean[df['language']!='en'].apply(translate_to_en)
Where I am trying to filter the column of language by the ones that aren't english and I want to translate the description_text_clean column. But in the end I obtain that the description_text_clean column have been modified in the english columns by NaN and I want them to continue as they were.
Example DataFrame:
df = pd.DataFrame([['Example text', 'en'],
['No es ingles', 'es'],
['I am again english', 'en']],
columns=['description_text_clean', 'language'])
Actual result:
description_text_clean language
0 NaN en
1 It is not English es
2 NaN en
The desired result will be to obtain a dataframe with all the texts translated to english with the translate_to_en function that uses google translate api:
description_text_clean language
0 Example text en
1 It is not English es
2 I am again english en
Any suggestion?