반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- aws cicd
- 도커
- codebuild
- aws
- Spring
- codepipeline
- bootstrap
- Jenkins
- java bigdecimal
- COALESCE
- Flux
- SQL
- codedeploy
- chart.js
- AWS CI/CD 구축하기
- chartjs
- IntelliJ
- Spring Error
- codedeploy error
- redis
- PostgreSQL
- kubeflow
- or some instances in your deployment group are experiencing problems.
- VPN
- Airflow
- docker
- JavaScript
- Kafka
- node
- Python
Archives
- Today
- Total
Small Asteroid Blog
파이썬에서 dataframe to postgresql 저장하기 본문
728x90
import sqlalchemy
from sqlalchemy import create_engine
engine = sqlalchemy.create_engine("postgresql://user:password@host:port/database")
df_tp.to_sql(name = 'tablename',
con = engine,
schema = 'public',
if_exists = 'replace', # {'fail', 'replace', 'append'), default 'fail'
index = True,
index_label = 'id',
chunksize = 2,
dtype = {
'id': sqlalchemy.types.INTEGER(),
'dominant': sqlalchemy.INTEGER(),
'contribution': sqlalchemy.types.Float(precision=3),
'topic': sqlalchemy.types.TEXT(),
'date': sqlalchemy.DateTime(),
'to_yn': sqlalchemy.types.Boolean(),
'docid': sqlalchemy.types.INTEGER()
})
- if_exists = 'fail' : 같은 이름의 Table이 존재할 경우 ValueError 가 남
- if_exists = 'replace': 같은 이름의 Table이 존재할 경우 기존 Table을 Drop하고 새로운 값을 Insert함
- if_exists = 'append': 같은 이름의 Table이 존재할 경우 기존 Table에 추가로 새로운 값을 Insert함
728x90
반응형
'백엔드 > Python' 카테고리의 다른 글
[python] Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-6g2r1v6o/gensim/ (0) | 2022.01.06 |
---|---|
[python] Please use the NLTK Downloader to obtain the resource (0) | 2021.11.26 |
리눅스에서 파이썬 가상환경 만들기 (0) | 2021.11.18 |
[python] postgresql insert into list 형 (0) | 2021.11.17 |
python 실행 시 매개변수 인자 전달하기 - sys argv (0) | 2021.11.17 |