我将数据从一个表加载到pandas中,然后将该数据插入到新表中。但是,我看到的不是普通的字符串值bytearray。在
bytearray(b'TM16B0I8')
应该是TM16B0I8
我做错什么了?在
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)....'
确保使用了正确的排序规则和编码。我碰巧在我的网站数据库表中使用了UTF8MB4_BIN。把它改成了utf8mb4_general_ci,它做到了。在
由于某些原因,pythonmysql连接器只返回bytearry(在(How return str from mysql using mysql.connector?)中有更多信息),但是可以使用
相关问题 更多 >
编程相关推荐