<i id='mlAl9'><tr id='mlAl9'><dt id='mlAl9'><q id='mlAl9'><span id='mlAl9'><b id='mlAl9'><form id='mlAl9'><ins id='mlAl9'></ins><ul id='mlAl9'></ul><sub id='mlAl9'></sub></form><legend id='mlAl9'></legend><bdo id='mlAl9'><pre id='mlAl9'><center id='mlAl9'></center></pre></bdo></b><th id='mlAl9'></th></span></q></dt></tr></i><div id='mlAl9'><tfoot id='mlAl9'></tfoot><dl id='mlAl9'><fieldset id='mlAl9'></fieldset></dl></div>

    <small id='mlAl9'></small><noframes id='mlAl9'>

      <bdo id='mlAl9'></bdo><ul id='mlAl9'></ul>

    1. <legend id='mlAl9'><style id='mlAl9'><dir id='mlAl9'><q id='mlAl9'></q></dir></style></legend>
      <tfoot id='mlAl9'></tfoot>
    2. 将 IBM_DB 与 Pandas 一起使用

      时间:2023-09-10

      <small id='z1NFu'></small><noframes id='z1NFu'>

      • <legend id='z1NFu'><style id='z1NFu'><dir id='z1NFu'><q id='z1NFu'></q></dir></style></legend>
          <bdo id='z1NFu'></bdo><ul id='z1NFu'></ul>
          <i id='z1NFu'><tr id='z1NFu'><dt id='z1NFu'><q id='z1NFu'><span id='z1NFu'><b id='z1NFu'><form id='z1NFu'><ins id='z1NFu'></ins><ul id='z1NFu'></ul><sub id='z1NFu'></sub></form><legend id='z1NFu'></legend><bdo id='z1NFu'><pre id='z1NFu'><center id='z1NFu'></center></pre></bdo></b><th id='z1NFu'></th></span></q></dt></tr></i><div id='z1NFu'><tfoot id='z1NFu'></tfoot><dl id='z1NFu'><fieldset id='z1NFu'></fieldset></dl></div>
            <tbody id='z1NFu'></tbody>

              • <tfoot id='z1NFu'></tfoot>

                本文介绍了将 IBM_DB 与 Pandas 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试使用 Python 语言的数据分析工具 Pandas.我正在尝试使用 ibm_db 包从 IBM DB 读取数据.根据 Pandas 网站上的文档,我们需要提供至少 2 个参数,一个是要执行的 sql,另一个是数据库的连接对象.但是当我这样做时,它给了我连接对象中没有 cursor() 方法的错误.我想也许这不是这个特定的 DB 包的工作方式.我试图找到一些解决方法,但没有成功.

                I am trying to use the data analysis tool Pandas in Python Language. I am trying to read data from a IBM DB, using ibm_db package. According to the documentation in Pandas website we need to provide at least 2 arguments, one would be the sql that would be executed and other would be the connection object of the database. But when i do that, it gives me error that the connection object does not have a cursor() method in it. I figured maybe this is not how this particular DB Package worked. I tried to find a few workarounds but was not successfull.

                代码:

                print "hello PyDev"
                con = db.connect("DATABASE=db;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=admin;PWD=admin;", "", "")
                sql = "select * from Maximo.PLUSPCUSTOMER"
                stmt = db.exec_immediate(con,sql)
                pd.read_sql(sql, db)
                print "done here"
                

                错误:

                hello PyDev
                Traceback (most recent call last):
                  File "C:Users
                ayworkspaceFirstprojectpack	est.py", line 15, in <module>
                    pd.read_sql(sql, con)
                  File "D:etllibsite-packagespandasiosql.py", line 478, in read_sql
                    chunksize=chunksize)
                  File "D:etllibsite-packagespandasiosql.py", line 1504, in read_query
                    cursor = self.execute(*args)
                  File "D:etllibsite-packagespandasiosql.py", line 1467, in execute
                    cur = self.con.cursor()
                AttributeError: 'ibm_db.IBM_DBConnection' object has no attribute 'cursor'
                

                如果我从数据库中获取数据,我可以获取数据,但我需要读入数据帧并需要在处理数据后写回数据库.

                I am able to fetch data if i fetch it from the database but i need to read into a dataframe and need to write back to the database after processing data.

                从数据库中获取的代码

                stmt = db.exec_immediate(con,sql)
                 tpl=db.fetch_tuple(stmt)
                 while tpl:
                     print(tpl)
                     tpl=db.fetch_tuple(stmt)
                

                推荐答案

                在进一步研究包的过程中,我发现我需要将IBM_DB连接对象包装在一个ibm_db_dbi连接对象中,这是https://pypi.org/project/ibm-db/ 包.

                On doing further studying the package, i found that I need to wrap the IBM_DB connection object in a ibm_db_dbi connection object, which is part of the https://pypi.org/project/ibm-db/ package.

                所以

                conn = ibm_db_dbi.Connection(con)
                df = pd.read_sql(sql, conn)
                

                上述代码有效,pandas 成功将数据提取到数据帧中.

                The above code works and pandas fetches data into dataframe successfully.

                这篇关于将 IBM_DB 与 Pandas 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将 Python 连接到 Db2 下一篇:SQLAlchemy Columns 结果处理

                相关文章

                最新文章

              • <legend id='75PJp'><style id='75PJp'><dir id='75PJp'><q id='75PJp'></q></dir></style></legend>

                <i id='75PJp'><tr id='75PJp'><dt id='75PJp'><q id='75PJp'><span id='75PJp'><b id='75PJp'><form id='75PJp'><ins id='75PJp'></ins><ul id='75PJp'></ul><sub id='75PJp'></sub></form><legend id='75PJp'></legend><bdo id='75PJp'><pre id='75PJp'><center id='75PJp'></center></pre></bdo></b><th id='75PJp'></th></span></q></dt></tr></i><div id='75PJp'><tfoot id='75PJp'></tfoot><dl id='75PJp'><fieldset id='75PJp'></fieldset></dl></div>

                <small id='75PJp'></small><noframes id='75PJp'>

                  <tfoot id='75PJp'></tfoot>
                    <bdo id='75PJp'></bdo><ul id='75PJp'></ul>