方法
刚开始使用xlrd模块去做 安装
pip install xlrd
查阅资料准备采用pandas库,其封装好了xlrd库
pandas读取xlsx
data = pd.read_excel(path, sheet_name=0, header=[0])
data.head()
遇到一个错误:
ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install
参考https://blog.csdn.net/qq_52684907/article/details/118995579 安装库openpyxl
pip install openpyxl
得到的数据DataFrame是一种表格的形式,可以转化为numpy.array
data = data.values
读取文件名是xlsx的文件列表
dir ='D:\\files_save\\code\\ANT_process\\data_use';
filelist = []
for i in os.listdir(dir):
path = os.path.join(dir, i)
if os.path.isfile(path):
if os.path.splitext(path)[1]==".xlsx":
filelist.append(i)
Tsub_num=len(filelist)
for sub_num in range(Tsub_num):
sub_name = filelist[sub_num];path = os.path.join(dir, sub_name)
|