python pandas read_excel 编码错误
文章目录
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence
io = r'C:\data.xls'
df1 = pd.read_excel(open(io,'r'),sheet_name='数据',dtype={'Stkcd':str})
在windows下,使用open(io,'rb')可以避免改报错;b的意思是 On Windows,'b'appended to the mode opens the file in binary mode, so there are also modes like'rb','wb', and'r+b'.
另外,dtype={'Stkcd':str} 可以指定相应列的格式
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论