Pandas中的DataFrame读取Oracle的方法

1.Oracle

需安装的包

cx_Oracle

pandas

 def GetQueryByDF(self,sql):
        conn = cx_Oracle.connect("orcl/orcl@localhost:1521/ORCL")  # 连接数据库
        cur = conn.cursor()
        cur.execute(sql)
        title = [i[0] for i in cur.description]
        res = cur.fetchall()
        cur.close()
        conn.close()
        result = pd.DataFrame(res,columns=title)
        return result

猜你喜欢

转载自www.cnblogs.com/want990/p/12284227.html
今日推荐