from sqlalchemy import create_engine import pandas as pd engine = create_engine(‘postgresql://user:pass@localhost/db_name‘) df = pd.read_csv(‘/path/to/csv_file‘) df.to_sql(‘pandas_db‘, engine也可以添加if_exists参数,用来替换或者添加到已有的数据表,e.g.
df.to_sql(‘pandas_db‘, engine, if_exists=‘replace‘)这个对添加文档同样适用。 相关文档请见: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
ERROR: type "geometry" does not exist原因是缺少postgis模块 · 解决方案: - 打开pgadmin - 选择工作的数据库 - 点击SQL添加命令 - 执行“CREATE EXTENSION postgis;”
持续更新...