DataFrame构造函数未正确调用

时间:2018-06-01 06:05:06

标签: python-3.x pandas dataframe pymysql

当我使用pymysql从数据库中检索数据并将其添加到pandas数据帧时,它会抛出异常'DataFrame构造函数未正确调用!'

rid=103
df1 = pd.DataFrame([])

try:
    with connection.cursor() as cursor:
        for qid in my_new_qid_list:
            sql = ("SELECT r_id,qid,is_right,is_attempted FROM assessment_results_answers WHERE result_id= %s AND qid=%s"%(rid,qid))
            # Execute the SQL command
            cursor.execute(sql)
            results = cursor.fetchall()
            df = DataFrame(results)
            df = df[['r_id', 'qid', 'is_right', 'is_attempted ']]
            df1 = df1.append(df)
except Exception as e:
   print(e)

我无法解决这个问题。

0 个答案:

没有答案