我正在将一张表中的数据加载到 pandas 中,然后将该数据插入到新表中。但是,我看到的不是普通的字符串值,而是字节数组。
bytearray(b'TM16B0I8')
它应该是TM16B0I8
我在这里做错了什么?
My code:
engine_str = 'mysql+mysqlconnector://user:pass@localhost/db'
engine = sqlalchemy.create_engine(engine_str, echo=False, encoding='utf-8')
connection = engine.connect()
th_df = pd.read_sql('select ticket_id, history_date', con=connection)
for row in th_df.to_dict(orient="records"):
var_ticket_id = row['ticket_id']
var_history_date = row['history_date']
query = 'INSERT INTO new_table(ticket_id, history_date)....'
由于某种原因,Python MySql 连接器仅返回 bytearrys,(更多信息在(如何使用 mysql.connector 从 mysql 返回字符串? https://stackoverflow.com/questions/27566078/how-return-str-from-mysql-using-mysql-connector) 但你可以将它们解码为 unicode 字符串
var_ticket_id = row['ticket_id'].decode()
var_history_date = row['history_date'].decode()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)