python - convert pandas dataframe to list of tuples and drop all pandas datatypes -


i need convert dataframe format can inserted sql table.

data_tuples = [tuple(row) row in df.values] 

how remove non python datatypes pandas dataframe (including np ints , nans , nats)?

if want efficiently, use corresponding pandas method - to_sql():

from sqlalchemy import create_engine  # conn = create_engine('postgresql://user:password@host:port/dbname') conn = create_engine('postgresql+psycopg2://user:password@host:port/dbname') df.to_sql('table_name', conn) 

where conn sqlalchemy engine connection object

docs: using sqlalchemy postgresql


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -