【问题标题】:Not able to insert data in AWS postgres RDS无法在 AWS postgres RDS 中插入数据
【发布时间】:2019-12-12 16:58:09
【问题描述】:

我无法通过 pandas to_sql 在 aws postgres 中添加 pandas 数据框

我尝试过一条一条地添加记录,它可以正常工作,但是当我尝试添加数据框时,它没有显示任何错误,也没有提交

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 纬度经度

0 1 纽约市 40.73 -73.93

1 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 纬度经度

0 1 纽约市 40.73 -73.93

1 100 abcdef 12.33 14.11

2 100 abcdef -12.33 14.11

【问题讨论】:

    标签: python postgresql amazon-web-services sqlalchemy amazon-rds


    【解决方案1】:

    下面链接的答案似乎建议在您的 to_sql 语句中添加架构参数:

    Pandas to_sql doesn't insert any data in my table

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 2021-02-12
      相关资源
      最近更新 更多