我正在寻找一种从 pandas 数据框创建 postgres 表的方法,然后直接在 pgAdmin 中读取 postgre 表。 多亏了这个链接,我找到了一种方法:How to write DataFrame to postgres table? .
命令是:
from sqlalchemy import create_engine
engine = create_engine('postgresql://username:password@host:port/database')
df.to_sql('table_name', engine)
但是,我不知道“table_name”是什么。我必须在我的数据库中创建一个表吗?
感谢您的帮助!
最佳答案
如果不存在具有您指定名称的表,将创建该表。 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
关于python - 如何从 Pandas 数据框创建 postgres 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53321078/