简体   繁体   English

无法在AWS Postgres RDS中插入数据

[英]Not able to insert data in AWS postgres RDS

I am unable to add pandas dataframe in aws postgres through pandas to_sql 我无法通过熊猫to_sql在AWS Postgres中添加熊猫数据框

I have tried adding one by one record and it works properly but when i try to add dataframe it doesn't shows any error and it is not committed 我尝试过一张一张地添加一条记录,并且工作正常,但是当我尝试添加数据框时,它没有显示任何错误并且没有提交

import pandas as pd 

import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

host="####.amazonaws.com"
port=5432
dbname="@@@@"
user="@@@@"
password="&&&&"

engine=create_engine("@@@@://@@@@:&&&&@####.amazonaws.com:5432/@@@@",
                       echo = True)

pd.read_sql("select * from Cities", engine)

id cityname latitude longitude id城市名纬度经度

0 1 New York City 40.73 -73.93 0 1纽约市40.73 -73.93

1 100 abcdef 12.33 14.11 1100 abcdef 12.33 14.11

2 100 abcdef -12.33 14.11 2 100 abcdef -12.33 14.11

tempdf = {'id': 1000, 'cityname': 'Delhi', 'latitude': '120', 'longitude': '110'}

tempdf = pd.DataFrame(list(tempdf.items()))

tempdf.to_sql(name='Cities', con=engine, index=False, if_exists='append')

pd.read_sql("select * from Cities", engine)

id cityname latitude longitude id城市名纬度经度

0 1 New York City 40.73 -73.93 0 1纽约市40.73 -73.93

1 100 abcdef 12.33 14.11 1100 abcdef 12.33 14.11

2 100 abcdef -12.33 14.11 2 100 abcdef -12.33 14.11

Answer linked below appears to suggest adding schema argument to your to_sql statement: 下面的答案链接似乎建议向您的to_sql语句添加架构参数:

Pandas to_sql doesn't insert any data in my table 熊猫to_sql在我的表中没有插入任何数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM