[英]How to create a postgres table from a pandas dataframe?
I'm looking for a way to create a postgres table from a pandas dataframe, and then read the postgre table directly in pgAdmin. 我正在寻找一种从熊猫数据框创建postgres表的方法,然后直接在pgAdmin中读取postgre表。 I've found a way to do that thanks to this link : How to write DataFrame to postgres table?
通过此链接,我找到了一种方法: 如何将DataFrame写入postgres表? .
。
The command is : 命令是:
from sqlalchemy import create_engine
engine = create_engine('postgresql://username:password@host:port/database')
df.to_sql('table_name', engine)
However, I don't know what is 'table_name'. 但是,我不知道什么是“ table_name”。 Do I have to create a table in my Data Base?
我必须在数据库中创建一个表吗?
Thanks for your help! 谢谢你的帮助!
A table with the name you specify will be created if it does not already exist. 如果您指定的表尚不存在,则将创建该表。 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.