|
这两个命令在时间执行上有区别:8 L/ k3 {! S+ Z+ Z* f0 h( t1 o2 |
import pandas as pddf=pd.read_sql_query('SELECT * FROM TABLE',conn)df=pd.read_sql_table(TABLE,conn)谢谢你的帮助! X; M6 C* _. x, [3 L' F; a
* F) d6 W/ Z8 w 解决方案: 6 z% U: R# g. F9 V2 f3 L
我想你不会注意到这种差异。
' G! l2 L$ a. i+ b( e% T* J' v4 o, U这是两个函数的源代码:
) I7 p' C0 l& J) C% e9 gIn [398]: pd.read_sql_query??Signature: pd.read_sql_query(sql,con,index_col=None,coerce_float=True,params=None,parse_dates=None,chunksize=None)Source:def read_sql_query(sql,con,index_col=None,coerce_float=True,params=None, parse_dates=None,chunksize=None): pandas_sql = pandasSQL_builder(con) return pandas_sql.read_query( sql,index_col=index_col,params=params,coerce_float=coerce_float, parse_dates=parse_dates,chunksize=chunksize)和( s; B5 Q% _: Y+ f5 }6 Z* l
In [399]: pd.read_sql_table??Signature: pd.read_sql_table(table_name,con,schema=None,index_col=None,coerce_float=True,parse_dates=None,columns=None,chunksize=None)Source:def read_sql_table(table_name,con,schema=None,index_col=None, coerce_float=True,parse_dates=None,columns=None, chunksize=None): con = _engine_builder(con) if not _is_sqlalchemy_connectable(con): raise NotImplementedError("read_sql_table only supported for " "SQLAlchemy connectable.") import sqlalchemy from sqlalchemy.schema import MetaData meta = MetaData(con,schema=schema) try: meta.reflect(only=[table_name],views=True) except sqlalchemy.exc.InvalidRequestError: raise ValueError("Table %s not found" % table_name) pandas_sql = SQLDatabase(con,meta=meta) table = pandas_sql.read_table( table_name,index_col=index_col,coerce_float=coerce_float, parse_dates=parse_dates,columns=columns,chunksize=chunksize) if table is not None: return table else: raise ValueError("Table %s not found" % table_name,con)注:我故意切断文档字符串… |
|