'Insertion of Pandas Dataframe with SQL on Azure cloud instead of local server, the code given below is working but taking too much time

This is working but taking to much time, anyone please give me any efficient piece of code instead of these.

print("Insertion of recodes has been started ")
    insert = 'INSERT INTO {} ('.format('TCTRIPS_BO') + ', '.join(df_trips.columns) + ') VALUES 
,df_trips['uploaded']=['0']*df_trips.shape[0]
    
    df_trips=df_trips.replace("'",'',regex=True)
    for i,row in df_trips.iterrows():
        values = map((lambda x: "'"+str(x)+"'"), row[:-1])
        inserting = insert +'('+ ', '.join(values) +');'
        cursor.execute(inserting )
    print('Inserted Record in Tctrip --->' + str(i+1))
    # cursor.commit()

I have tried this but get error, link for this method https://www.dataquest.io/blog/sql-insert-tutorial/

    from sqlalchemy import create_engine

# create sqlalchemy engine
engine = create_engine("mysql+pymysql://{user}:{pw}@localhost/{db}"
                       .format(user="root",
                               pw="12345",
                               db="employee"))
    df_trips.to_sql('TCTRIPS_BO', con = engine, if_exists = 'append', chunksize = 1000)
Got this Error lines
(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([WinError 
10061] No connection could be made because the target machine actively refused it)")

This is another error:

invalid literal for int() with base 10: 'atg-prod.database.windows.net'

I think my database in not on local server that why it is creating problems,

I have got another solution on stack Overflow but I unable to change my code according to that one, Link for that solution https://stackoverflow.com/questions/13020908/sql-multiple-inserts-with-python


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source