# -*- coding: utf-8 -*- """ Created on Fri Apr 30 09:19:24 2021 @author: charles """ import chardet import csv def read_csv(filename): encodings = ['gbk','utf-8','utf-8-sig','GB2312','gb18030',] for e in encodings: data = [] try: with open(filename, encoding=e) as f: reader = csv.reader(f) #print(reader) #header = next(reader) #print(header) for row in reader: data.append(row) print(row) print(filename,e) return data except: print(filename,e) #print(filename,"==================") if __name__ == '__main__': path = "C:/Users/charles/Desktop/1.csv" f = open(path,'rb') data = f.read() print(chardet.detect(data)) df=read_csv(path)