鱼C论坛

 找回密码
 立即注册
查看: 1502|回复: 2

[已解决]python读取csv文件

[复制链接]
发表于 2018-2-3 11:50:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
想要读取csv文件(只包含英文和数字):
import pandas as pd
df = pd.read_csv('TRD_Mnth.csv')

报错信息是:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

请问应该如何解决呢?
最佳答案
2018-2-3 13:39:40
你的TRD_Mnth.csv存放的二进制数据?
先试试 df = pd.read_csv('TRD_Mnth.csv','rb')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-3 13:39:40 | 显示全部楼层    本楼为最佳答案   
你的TRD_Mnth.csv存放的二进制数据?
先试试 df = pd.read_csv('TRD_Mnth.csv','rb')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-2-3 14:08:37 | 显示全部楼层
yjsx86 发表于 2018-2-3 13:39
你的TRD_Mnth.csv存放的二进制数据?
先试试 df = pd.read_csv('TRD_Mnth.csv','rb')

就是股票代码、日期和收益率的数据
加上‘rb‘’可以打开了!虽然还有一条warning信息:
ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
  df = pd.read_csv('TRD_Mnth.csv','rb')
谢谢您的指导!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-17 20:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表