Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法创建第二个数据帧_Python_Pandas_Pyodbc - Fatal编程技术网

Python 无法创建第二个数据帧

Python 无法创建第二个数据帧,python,pandas,pyodbc,Python,Pandas,Pyodbc,我的第二个数据帧在创建时没有加载值。关于它为什么不起作用有什么帮助吗?当我将光标设置为一个列表时,其中包含一组值,但无论出于何种原因,当我第二次尝试使用pandas加载正常数据帧时,它都不起作用 我的代码: conn = pyodbc.connect(constr, autocommit=True) cursor = conn.cursor() secondCheckList = [] checkCount = 0 maxValue = 0 str

我的第二个数据帧在创建时没有加载值。关于它为什么不起作用有什么帮助吗?当我将光标设置为一个列表时,其中包含一组值,但无论出于何种原因,当我第二次尝试使用pandas加载正常数据帧时,它都不起作用

我的代码:

    conn = pyodbc.connect(constr, autocommit=True)
    cursor = conn.cursor()
    secondCheckList = []
    checkCount = 0
    maxValue = 0
    strsql = "SELECT * FROM CRMCSVFILE"
    cursor = cursor.execute(strsql)
    cols = []
    SQLupdateNewIdField = "UPDATE CRMCSVFILE SET NEW_ID = ? WHERE Email_Address_Txt = ? OR TELEPHONE_NUM = ? OR DRIVER_LICENSE_NUM = ?"
    for row in cursor.description:
        cols.append(row[0])
    df = pd.DataFrame.from_records(cursor)
    df.columns = cols
    newIdInt = 1
    for row in range(len(df['Email_Address_Txt'])):
        #run initial search to figure out the max number of records. Look for email, phone, and drivers license, names have a chance not to be unique
        SQLrecordCheck = "SELECT * FROM CRMCSVFILE WHERE Email_Address_Txt = '" + str(df['Email_Address_Txt'][row]) + "' OR TELEPHONE_NUM = '" + str(df['Telephone_Num'][row]) + "' OR DRIVER_LICENSE_NUM = '" + str(df['Driver_License_Num'][row]) + "'"
##        print(SQLrecordCheck)
        cursor = cursor.execute(SQLrecordCheck)
## maxValue is indeed a list filled with records
            maxValue =(list(cursor))
## THIS IS WHERE PROBLEM OCCURS
        tempdf = pd.DataFrame.from_records(cursor)

为什么不直接使用pd.read\u sql\u查询(“your\u query”,conn)呢?这将以数据帧的形式返回查询结果,并且需要的代码更少。另外,在顶部将cursor设置为cursor.execute(strsql),然后尝试在for循环中再次调用cursor上的execute,但不能再调用cursor上的execute,必须再次设置cursor=conn.cursor()

光标输出什么?哦,我不知道(熊猫/数据库一般都不知道)谢谢你通知我!!!当我有机会尝试时,我会让你知道它是否有效!嘿,只是想跟进一下,执行多个静默不需要再次设置cursor=conn.cursor()。execute语句可以根据需要多次使用!不管出于什么原因,maxValue=list(游标)就是把我的代码弄得一团糟的那一行,如果我去掉它,它会工作得很好。