[英]Can I import a table from SQL Server (=MS SQL) into a Python / Pandas data frame?
I am using Matlab
and its ' datasets
', and R
and its ' dataframes
'. 我正在使用
Matlab
及其“ datasets
”,以及R
及其“ dataframes
”。
I am thinking of using Python but I need an equivalent data-storing format. 我正在考虑使用Python,但我需要一个等效的数据存储格式。 Extension 'Pandas' for Python has a class called dataframe which is similar.
Python的扩展“Pandas”有一个名为dataframe的类,它类似。
Now I would like to be able to send a query to a SQL Server and store the result of that query in a Panda Dataframe 现在我希望能够向SQL Server发送查询并将该查询的结果存储在Panda Dataframe中
eg: newDataFrame = GetDataFrameFromSQLServer('SELECT * from schema.table',sqlConnection)
例如:
newDataFrame = GetDataFrameFromSQLServer('SELECT * from schema.table',sqlConnection)
I had the impression that Pandas only talks to SQLite. 我的印象是Pandas只与SQLite交谈。 Is that the case?
是这样的吗?
I believe pandas can handle any reading from any DB API v2.0 compliant data source. 我相信pandas可以处理来自任何符合DB API v2.0的数据源的任何读取。 Have a look at
pandas.io.sql
( link ) for a bunch of functions that facilitate this. 看看
pandas.io.sql
( link )中的一堆函数可以实现这一点。
One thing to note, is that writing to a database requires a "flavor" where that flavor defaults to sqlite
, but in the write_frame
definition possible values are {'sqlite', 'mysql', 'oracle'}
. 需要注意的一点是,写入数据库需要一个“味道”,其味道默认为
sqlite
,但在write_frame
定义中,可能的值是{'sqlite', 'mysql', 'oracle'}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.