python - ValueError with Pandas - shaped of passed values -


i'm trying use pandas , pyodbc pull sql server view , dump contents excel file.

however, i'm getting error when dumping data frame (i can print colums , dataframe content):

valueerror: shape of passed values (1, 228), indices imply (2, 228) 

there several other issues on forum pertaining same issue, none discuss pulling sql server table.

i can't figure out causing error, , altering view cast source columns differently has no effect.

here python code i'm using:

import pyodbc import pandas pd cnxn = pyodbc.connect('driver={sql server};server=servername;database=dbname;uid=username;pwd=password') cursor = cnxn.cursor() script = """ select * schema.activeenrollmentcount """ cursor.execute(script) columns = [desc[0] desc in cursor.description]  data = cursor.fetchall()  df = pd.dataframe(list(data), columns=columns)  writer = pd.excelwriter('c:\temp\activeenrollment.xlsx') df.to_excel(writer, sheet_name='bar')  writer.save() 

the 2 columns i'm trying pull both 3-digit integers.

to query data database, can better use built-in read_sql_query function instead of doing execute , converting dataframe manually.
example, give like:

df = pd.read_sql_query(script, cnxn) 

see docs more explanation on read_sql/to_sql.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -