Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'.

I am thinking of using Python but I need an equivalent data-storing format. Extension 'Pandas' for Python has a class called dataframe which is similar.

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

e.g.: newDataFrame = GetDataFrameFromSQLServer('SELECT * from schema.table',sqlConnection)

I had the impression that Pandas only talks to SQLite. Is that the case?

like image 618
pumpkin Avatar asked Jun 15 '26 03:06

pumpkin


1 Answers

I believe pandas can handle any reading from any DB API v2.0 compliant data source. Have a look at pandas.io.sql(link) for a bunch of functions that facilitate this.

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'}.

like image 50
tshauck Avatar answered Jun 17 '26 17:06

tshauck