您可以
to_sql用来将数据推送到Redshift数据库。通过使用SQLAlchemy引擎与数据库的连接,我已经能够做到这一点。只要确保
index =False在
to_sql通话中进行设置即可。如果该表不存在,则将创建该表,并且您可以指定是否要调用以替换该表,追加到该表,或者如果该表已存在则失败。
from sqlalchemy import create_engineimport pandas as pdconn = create_engine('postgresql://username:[email protected]:5439/yourdatabase')df = pd.Dataframe([{'A': 'foo', 'B': 'green', 'C': 11},{'A':'bar', 'B':'blue', 'C': 20}])df.to_sql('your_table', conn, index=False, if_exists='replace')
请注意,您可能需要
pip installpsycopg2通过SQLAlchemy连接到Redshift。
to_sql文档
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)