Created
May 4, 2020 22:28
-
-
Save erikerlandson/cd7b682449d711d90d9f6737461aafb7 to your computer and use it in GitHub Desktop.
writing pandas data into postgresql using sqlalchemy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
data = pd.DataFrame(list(range(100)), columns=["data"]) | |
pip install psycopg2 | |
import sqlalchemy | |
from sqlalchemy import create_engine | |
import psycopg2 | |
cxstr = 'postgresql://{user}:{passwd}@{host}:5432/{db}'.format( \ | |
user='xxx', \ | |
passwd='xxx', \ | |
host='postgresql', \ | |
db='demodb') | |
engine = create_engine(cxstr) | |
data.to_sql('demo', engine, if_exists='replace', index = False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment