Home > Software engineering >  Is there any way to export pandas dataframe into database with existing tables?
Is there any way to export pandas dataframe into database with existing tables?

Time:05-30

Dear Stackoverflow Community, i'm trying to export my dataframe into postgresql database, i used SQLAlchemy but it doesnt give me the opportunity to map the dataframe with the existing tables in the database, for exemple this mt dataframe:

ClientNumber ClientName Amout
        1000     Albert   5000     
        2000       John   4000
        1200   Cristian   1000

and the database have this table :

id_client  client_name   client_amount
     1000       Albert            5000     
     2000         John            4000
     1200     Cristian            1000

The question is how to link my dataframe to postgresql without forcing to change the name columns of the dataframe ? Thanks in advance

CodePudding user response:

i've been there before and i think you need to use PygramETL it has the features that you need

CodePudding user response:

Use rename and set inplace argument to False

df_data.rename(columns = {'ClientNumber':'id_client', 'ClientName':'client_name','Amout':'client_amount'}, inplace = False).to_sql(name = 'sql_table_name', con = con, if_exists = 'append')
  • Related