python-pandas and databases like mysql-open source projects pydata/pandas
Keith C Campbell
As Wes says, io/sql’s read_sql will do it, once you’ve gotten a database connection using a DBI compatible library. Here’s a short example using the MySQLdb and cx_Oracle libraries to connect to Oracle and MySQL and query their data dictionaries:
import pandas as pd
import cx_Oracle
ora_conn = cx_Oracle.connect('your_connection_string')
df_ora = pd.read_sql('select * from user_objects', con=ora_conn)
print 'loaded dataframe from Oracle. # Records: ', len(df_ora)
ora_conn.close()
import MySQLdb
mysql_cn= MySQLdb.connect(host='myhost',
port=3306,user='myusername', passwd='mypassword',
db='information_schema')
df_mysql = pd.read_sql('select * from VIEWS;', con=mysql_cn)
print 'loaded dataframe from MySQL. records:', len(df_mysql)
mysql_cn.close()