I use pandas library to write data which I retrieve from sql table. It is working but I don't see a column names there. Also each row is appended in Excel like
('aa','aa','01/10/2019','zzz')
('bb','cc','03/10/2019','yy')
..
I want my Excel sheet with column names and without colon.(') A proper excel sheet.
eg:
Name Address Date product
aa aa 01/10/2019 zzz
My code is as follows;
cursor.execute(sql, values)
records = cursor.fetchall()
data = []
for row in records:
data.append(row)
df = pd.DataFrame(data)
cursor.close()
cnxn.close()
writer = pd.ExcelWriter('output.xlsx')
df.to_excel(writer, index=False, sheet_name='Invoice')
writer.save()
How can I retrieve with column names and write that in excel using pandas?
I use pyodbc to connect to the SQL Server database.