首页 > 解决方案 > Geopandas:AttributeError:“事务”对象没有属性“run_callable”

问题描述

我需要有关此错误的帮助,AttributeError: 'Transaction' object has no attribute 'run_callable'

from sqlalchemy import create_engine
import pandas as pd


def insert(df):
    calidades_df = df.copy()
    calidades_df.insert(loc=0, column='proceso', value=p['proceso'])
    calidades_df.insert(
        loc=len(calidades_df.columns),
        column='baja',
        value=False)

    engine = create_engine(
        "postgres://usr:pass#@localhost:5432/database"
    )
    with engine.begin() as conn:
        calidades_df.to_postgis(
            'calidades',
            conn,
            schema='ndvi',
            if_exists='append',
            index=False
            )

仅当使用带有 to_postgis() 函数的 geopandas 数据框时才会发生该错误。使用 to_sql() 函数的 pandas 数据帧可以正常工作。提前致谢

标签: pythonpython-3.xdataframesqlalchemygeopandas

解决方案


我偶然发现了同样的问题,似乎to_postgis()方法有点坏了。所以我所做的是实现使用from pandas的https://gis.stackexchange.com/a/239231/36712 。to_sql()您只需要将您的几何图形转换WKT为几何列并为它定义一个 dtype。


推荐阅读