0

I have a pandas dataframe, I can add a table to SQL with this :

 df.to_sql(table_name, engine, if_exists='append')

But since I don't want to have overlapping data for the same date column, I need to merge the new data AND to update indexes.

Consider current DB

index     date        value
     0    1-1-2002     15
     1    1-2-2002     34

Now I have a new pandas df to add:

index     date        value
     0    1-2-2002     34
     1    1-3-2002     12

I need to get at the end :

index     date        value
     0    1-1-2002     15
     1    1-2-2002     34
     2    1-3-2002     12

Is there a simple way to insert my pandas to the Postgresql (I am using sqlalchemy)

baltiturg
  • 164
  • 7
  • thanks, but that's not what I was after, maybe I didn't explain it right but in my case all rows are always different, no row merge is needed, just to avoid duplicates. I just want to avoid inserting 2 rows with the same date, and not to merge these rows (since they will be the same). – baltiturg Jan 18 '22 at 15:28

0 Answers0