I am reading data into pandas from an SQL Server 2014 12.0.4100 SP1 database. The data is stored in the Windows-1252 encoding.
I am using python 2.7.
I want to output the resulting dataframe to Excel or csv. Specifically:
import pyodbc
cnxn = pyodbc.connect(r'Driver={SQL Server};Server=.\my_server;Database=my_db;Trusted_Connection=yes;')
sql = "select * from my_table"
df = pd.read_sql(sql, cnxn)
df.to_csv("my_csv.csv", encoding="utf-8")
However, this fails with the error message:
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 13966: invalid start byte
What do I need to do to successfully export to a utf-8 csv?