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
Comments
Post a Comment