python各类错误提示

目录

  • 报错1:'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte
    • 解决方法1
    • 解决方法2
  • 报错2:ValueError: Value must be either numerical or a string containing a wildcard
    • 解决方法:检查相应文件是否开了筛选,将筛选清除

报错1:‘utf-8’ codec can’t decode byte 0xc1 in position 0: invalid start byte

'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte

解决方法1

fdata = pd.read_csv(fpath,encoding='gb18030')

可以尝试多种格式,比如:encoding=‘gbk’ 或者encoding='ISO-8859-1’等

解决方法2

使用Python的chartdet包先识别文件的类型,再定义encoding的值

import chardet

def guess_encoding(file_path):
    with open(file_path, 'rb') as f:
        result = chardet.detect(f.read())
        return result['encoding']

报错2:ValueError: Value must be either numerical or a string containing a wildcard

读取表格文件时,报错

ValueError: Value must be either numerical or a string containing a wildcard

解决方法:检查相应文件是否开了筛选,将筛选清除

你可能感兴趣的:(python,python)