from pandas import DataFrame
import pyodbc
cnxn = pyodbc.connect(databasez)
cursor.execute("""SELECT ID, NAME AS Nickname, ADDRESS AS Residence FROM tablez""")
DF = DataFrame(cursor.fetchall())
This is fine to populate my pandas DataFrame. But how do I get
DF.columns = ['ID', 'Nickname', 'Residence']
straight from cursor? Is that information stored in cursor at all?
You can get the columns from the cursor description:
columns = [column[0] for column in cursor.description]