python - 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 数据帧可以正常工作。提前致谢
解决方案
我偶然发现了同样的问题,似乎to_postgis()
方法有点坏了。所以我所做的是实现使用from pandas的https://gis.stackexchange.com/a/239231/36712 。to_sql()
您只需要将您的几何图形转换WKT
为几何列并为它定义一个 dtype。
推荐阅读
- reactjs - 在类组件中反应 useForm 等效项
- scikit-learn - 可视化 predict_proba 进行多类分类
- java - 不能使 Spring 方面的最低顺序
- react-native - Redux 持久化 Moment.js 日期对象以及字符串化和解析 Moment.js
- mysql - MySQL 从生日开始检查年龄
- javascript - 使用比率对数组进行排序
- python - 将 3 维数组的形状减少为 2 维数组或 DataFrame,但将轴的条目作为列表嵌套在另一个轴中
- c++ - 如何将 boost::hana::map 转换为 lambdas
- reactjs - 如何为服务器上部署的 Reactjs 应用程序设置环境变量?
- c# - 使用 windbg 调试 .NET OutOfMemoryException