我正在从MySQL数据库查询结果中创建两个数据帧,稍后我将它们连接到一个列上并获得最终结果。
以下是我目前的代码
import MySQLdb
from sqlalchemy import create_engine
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="M@nUtd10", # your password
db="Mediator") # name of the data base
cur = db.cursor()
from pandas import DataFrame
cur.execute("SELECT invoice_ref_2 AS PPS_Id ,cast(total_amount AS char(10)) AS Amount FROM core_invoices WHERE client_ref_id like 'payment_gc_sale%' AND partition_key = 20161129")
invoices_res = DataFrame(cur.fetchall())
invoices_res.columns = cur.keys()
cur.execute("SELECT invoice_ref_2 AS PPS_Id ,cast(total_amount AS char(10)) AS Amount FROM core_invoices WHERE client_ref_id like 'payment_gc_sale%' AND partition_key = 20161129")
accrual_res = DataFrame(cur.fetchall())
accrual_res.columns = cur.keys()
final_res = invoices_res.merge(accrual_res, on='PPS_Id')
db.close()
当我执行我得到的代码时,
“PandasError:未正确调用DataFrame构造函数!”
请协助。