2016-10-18 4 views
2

두 번째 데이터 프레임을 만들 때 값을로드하지 않습니다. 왜 작동하지 않는지에 대한 도움이 필요하십니까? 내가 커서를 목록으로 만들 때, 그 안에는 많은 가치가 있지만, 판다를 사용하여 정상적인 데이터 프레임로드를 시도 할 때 어떤 이유로 든 작동하지 않습니다.두 번째 데이터 프레임을 만들 수 없습니다. 파이썬 팬더

내 코드 :

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) 
+0

커서는 무엇을 출력합니까? –

답변

3

왜 그냥은 dataframe 같이 쿼리의 결과를 반환하고 적은 코드를 필요로합니다 pd.read_sql_query ("your_query"코네티컷)를 사용하지 마십시오. 또한 커서를 위에 cursor.execute (strsql)로 설정하면 for 루프에서 다시 execute를 호출하려고 시도하지만 더 이상 execute on cursor를 호출 할 수 없으므로 cursor = conn.cursor()를 설정해야합니다. 다시.

+0

우 나는 그 사실을 알지 못했다. (팬더/데이터베이스 전반에 대해) 새로운 정보를 주셔서 감사합니다 !!! 나는 그것을 시도 할 기회가 생겼을 때 그것이 작동 할 때/내가 알릴 것이다! – BLang

+0

안녕하십니까. 후속 조치를 원했기 때문에 여러 quieries를 실행하기 위해 cursor = conn.cursor()를 다시 설정할 필요가 없습니다. execute 문은 필요할 때 여러 번 사용할 수 있습니다! 어떤 이유로 든 maxValue = list (cursor)는 내 코드를 엉망으로 만든 라인이었습니다. – BLang

관련 문제