美文网首页
2018-08-30 python+pandas读取csv文件失

2018-08-30 python+pandas读取csv文件失

作者: 阿康666666 | 来源:发表于2018-08-30 13:27 被阅读82次

    使用python+pandas读入excel CSV格式文件时,直接用文件路径读取:

    pd.read_csv(FilePath)
    

    提示以下错误:

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 0: invalid continuation byte

    检查以后发现csv内容里面,除了各列数据外,在最顶端还有两行解释的内容,需要将其删除。

    同时,需要更换编码格式。参考stackoverflow 给出的解答,将utf-8改为"ISO-8859-1"即可。

    另外,因为我的csv中包含中文内容,需要改为GBK
    应该改为:

    pd.read_csv(FilePath,encoding='GBK')
    

    改了以后成功读入数据。

    相关文章

      网友评论

          本文标题:2018-08-30 python+pandas读取csv文件失

          本文链接:https://www.haomeiwen.com/subject/pxirwftx.html