【发布时间】:2017-04-16 17:20:47
【问题描述】:
我正在将一个表中的数据加载到 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)....'
【问题讨论】:
-
你在哪里看到字节数组?与上述代码相关的任何地方?
-
所以当我打印
th_df['ticket_id']时,不是给我一个字符串'TM16A0JY',而是给我这个数组[77, 83, 90, 45, 48, 50, 53, 52, 57, 56],当我查看数据库时插入之后它显示@987654327 @。有趣的是,对于整数 ID,它没有显示 bytearray,也没有在 db 中插入一个整数值。4567.
标签: python mysql python-3.x pandas sqlalchemy