{"id":7869,"date":"2015-11-02T23:38:05","date_gmt":"2015-11-02T23:38:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/02\/python-pandas-and-databases-like-mysql-open-source-projects-pydata-pandas\/"},"modified":"2015-11-02T23:38:05","modified_gmt":"2015-11-02T23:38:05","slug":"python-pandas-and-databases-like-mysql-open-source-projects-pydata-pandas","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/02\/python-pandas-and-databases-like-mysql-open-source-projects-pydata-pandas\/","title":{"rendered":"python-pandas and databases like mysql-open source projects pydata\/pandas"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/16ae5287b05cfce5fd3913be8f416161?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Keith C Campbell<\/strong><\/p>\n<p>As Wes says, io\/sql&#8217;s read_sql will do it, once you&#8217;ve gotten a database connection using a DBI compatible library. Here&#8217;s a short example using the MySQLdb and cx_Oracle libraries to connect to Oracle and MySQL and query their data dictionaries:<\/p>\n<pre><code>import pandas as pd\nimport cx_Oracle\n\nora_conn = cx_Oracle.connect('your_connection_string')\ndf_ora = pd.read_sql('select * from user_objects', con=ora_conn)    \nprint 'loaded dataframe from Oracle. # Records: ', len(df_ora)\nora_conn.close()\n\n\nimport MySQLdb\nmysql_cn= MySQLdb.connect(host='myhost', \n                port=3306,user='myusername', passwd='mypassword', \n                db='information_schema')\ndf_mysql = pd.read_sql('select * from VIEWS;', con=mysql_cn)    \nprint 'loaded dataframe from MySQL. records:', len(df_mysql)\nmysql_cn.close()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Keith C Campbell As Wes says, io\/sql&#8217;s read_sql will do it, once you&#8217;ve gotten a database connection using a DBI compatible library. Here&#8217;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(&#8216;your_connection_string&#8217;) df_ora = pd.read_sql(&#8216;select [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7869","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7869"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7869\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}