AttributeError: 模块“pandas.io.sql”没有属性“frame_query”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38487878/
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
AttributeError: module 'pandas.io.sql' has no attribute 'frame_query'
提问by SaikiHanee
I am trying to read a posgresql table into a python data frame using following code.
我正在尝试使用以下代码将 posgresql 表读入 python 数据框。
import psycopg2 as pg
import pandas.io.sql as psql
connection = pg.connect("dbname=BeaconDB user=admin password=root")
dataframe = psql.frame_query("SELECT * from encounters", connection)
But I get AttributeError: module 'pandas.io.sql' has no attribute 'frame_query'
How can I fix this?
但我得到了AttributeError: module 'pandas.io.sql' has no attribute 'frame_query'
如何解决这个问题?
采纳答案by NuclearPeon
Looking at the pandas.io.sql source, there is no frame_query.
查看pandas.io.sql源码,没有frame_query。
https://github.com/pydata/pandas/blob/master/pandas/io/sql.py
https://github.com/pydata/pandas/blob/master/pandas/io/sql.py
Documentation for pandas.io.sql is here: http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries
pandas.io.sql 的文档在这里:http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries
I've looked at pandas documentation from 0.12.0 to latest and the only references to frame_query
I've found has been to its deprecation.
我查看了从 0.12.0 到最新版本的 Pandas 文档,frame_query
我发现的唯一参考是它的弃用。
I found this SO answer which may address your concerns: https://stackoverflow.com/a/14511960/1703772
我发现这个 SO 答案可以解决您的问题:https: //stackoverflow.com/a/14511960/1703772
However, if you are using pandas version ~ 0.10 when 0.18.1 is available, I have to ask why.
但是,如果您在 0.18.1 可用时使用 Pandas 版本 ~ 0.10,我不得不问为什么.
回答by Michel Kluger
Such approach is deprecated,
这种方法已被弃用,
https://pandas.pydata.org/pandas-docs/version/0.15.2/generated/pandas.io.sql.write_frame.html
https://pandas.pydata.org/pandas-docs/version/0.15.2/generated/pandas.io.sql.write_frame.html
use instead: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html
改用:https: //pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html