打开txt文件遇到问题:
df = pd.read_csv("Desktop/test.txt",delimiter="\t",encoding = 'uft-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
解决方案有两个:
- 改为utf-16:
df = pd.read_csv("Desktop/test.txt",delimiter="\t",encoding = 'utf-16')
- python 自带库转化一下
with open('Desktop/test.txt', 'rb') as f:
contents = f.read()
with open("Desktop/test2.txt","w") as f:
f.write(contents.decode("utf-16") )
网友评论