[Python] How to improve code performance ( using Google Translate API )

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    import time
    start = time.time()
    import pandas as pd
    from deep_translator import GoogleTranslator

    data = pd.read_excel(r"latestdata.xlsx")
    translatedata = data['column']. fillna('novalue')

    list = []
    for i in translatedata:
    finaldata = GoogleTranslator(source='auto', target='english').translate(i)
    print(finaldata)
    list.append(finaldata)

    df = pd.DataFrame(list, columns=['Translated_values'])
    df.to_csv(r"jobdone.csv", sep= ';')

    end = time.time()

    print(f"Runtime of the program is {end - start}")


    I have data of 220k points and trying to translate a column data At first I tried to use pool method parallel program but got an error that I can not access API several time at once. My question is if there is other way to improve performance of code that I have right now.

    # 4066.826668739319 with just 10000 data all together.
    # 3809.4675991535187 computation time when I run in 2 batch's of 5000

    Continue reading...

Compartilhe esta Página