I am reading from SQL using sqlalchemy
q = """select * from table_name"""
data = pd.read_sql_query(q,con)
It appears ok when I view the results on screen
but when I assign it to a variable and write back to sql, it comes odd looking
string_oi = data.iloc[0,8]
df = pd.DataFrame({'test':[string_oi]})
df.to_sql(
name= 'tableTest',
con = con,
if_exists='replace',
index = False
)
con.commit()
When I define the string directly, it goes to SQL correctly
string_oi = 'Tylerâs way'
Examining the string when read from sql, the apostrophe is encoded as x80x99
, ie
'Tylerâx80x99s way'
How can I save/convert it so that strings are read correctly, which will then be ok when saving back to SQL? Presumably, this will happen with other special characters when reading the SQL table, and I would like to take care of this in a single step