python读取xlsx转csv文件出错
因为python读取xlsx文件的时间较长,然后想通过转csv的方式来缩短时间,陆续出现了很多玄学问题。
直接改后缀,出现以下问题:
ParserError: Error tokenizing data. C error: Expected 1 fields in line 11, saw 4
按照网上的解决方法,加上:
header=None,sep = None
又出现下列问题:
utf-8 codec cant decode byte 0x87 in position 10: invalid start byte
以及warning
ParserWarning: Falling back to the python engine because the c engine does not support sep=None with delim_whitespace=False; you can avoid this warning by specifying engine=python.
这里,加上engine=python,waring就会消失,将encoding = utf-8改成gbk也好还是什么,都会报错。
UnicodeDecodeError: gbk codec cant decode byte 0xf9 in position 56: illegal multibyte sequence
中途试过打开xlsx文件,在wps里选择另存为.csv文件,然后还是报错。
试完上面一圈的流程后,我开始考虑是不是路径有中文的问题,好的也不是。
最后想着试最后一遍,再另存了一次csv,这次终于ok了。
import pandas as pd df = pd.read_csv(D:/desktop/光谱/data.csv)#读取.csv文件 data = df.values #dark为除了第一行以外的数据 print(data.shape)
(16382, 20)