pandas.read_sql_table(table_name,con,schema = None,index_col = None,coerce_float = True,parse_dates = None,columns = None,chunksize = None )源代码
通过数据库表名读入DataFrame。
给定一个表名和一个可连接SQLAlchemy,返回一个DataFrame。此功能不支持DBAPI连接。
参数: | table_name:string 数据库中SQL表的名称。 con:SQLAlchemy可连接(或数据库字符串URI) 不支持SQLite DBAPI连接模式。 schema:string,默认无 要查询的数据库中的SQL模式的名称(如果数据库flavor支持此功能)。 如果为None(默认值), 则使用默认架构。 index_col:字符串或字符串列表,可选,默认值:无 要设置为索引的列(MultiIndex)。 coerce_float:boolean,默认为True 尝试将非字符串,非数字对象(如decimal.Decimal)的值转换为浮点值。 可能导致精度损失。 parse_dates:list或dict,默认值:None 要解析为日期的列名列表。 {column_name: format string}格式的字典,其中, 格式字符串在解析字符串时间时是与strftime兼容的, 或者在解析整数时间戳时是(D、s、ns、ms、us)兼容的。 {column_name: arg dict}格式的字典,其中arg dict对应于关键字参数, 特别适用于没有本机Datetime支持的数据库,例如SQLite。 columns:list,默认值:None 从SQL表中选择的列名列表 chunksize:int,默认无 如果指定,则返回一个迭代器,其中chunksize是要包含在每个块中的行数。 |
返回: | DataFrame(数据帧) |
例如,
import MySQLdb
conn= MySQLdb.connect(host='myhost',
port=3306,user='myusername', passwd='mypassword',
db='information_schema') resp = pd.read_sql_table(table_name = 't_line',con = conn,parse_dates = 'time',index_col = 'time',columns = ['a','b','c']) conn.close()