pandas ProgrammingError: (psycopg2.ProgrammingError) 无法适应类型“dict”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43141620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'dict'
提问by Nayana Madhu
I'm trying to insert a dataframe using the query
我正在尝试使用查询插入数据框
engine = create_engine('scot://pswd:xyz@ hostnumb:port/db_name')
dataframe.to_sql('table_name', engine, if_exists='replace')
but one column is a dictionary and I'm unable to insert it, only the column name is getting inserted.
I tried to change the type of the column in postgresfrom text to json object. still not able to insert.
I tried to use json.dumps()but still facing the issue.getting an error as "dtype: object is not JSON serializable"
但是一列是字典,我无法插入它,只有列名被插入。
我试图将postgres 中列的类型从文本更改为 json 对象。仍然无法插入。
我尝试使用json.dumps()但仍然面临问题。得到一个错误为“dtype: object is not JSON serializable”
回答by shathi
Try specifying the dtype. So in your example, you would say
尝试指定 dtype。所以在你的例子中,你会说
dataframe.to_sql('table_name', engine, if_exists='replace',dtype =
{'relevant_column':sqlalchemy.types.JSON})