Search code examples
pythontranslatedeepl

Translate dataframe with DeepL


I would like to translate (using DeepL) the text inside the df ["text"] column, where in each line there is a sentence. The text is not written in a single language, so I'd like to automatically detect the language of the text and put the translation in a new column called df ["translated"].

Thank you

I have DeepL's free authentication key but I can't figure out how to use it, I am a rookie.


Solution

  • You can use the DeepL-Python library.

    According to the documentation you can just ommit the parameter source_lang and it will try to detect the language by its own.

    import deepl
    translator = deepl.Translator(auth_key)
    result = translator.translate_text(text_to_translate)
    translated_text = result.text