如何通过python批量读取数据?
import pandas as pd
import os
def f1():
path = 'C:/Users/Administrator/Desktop/数据文件' #输入文件存储路径
folder = os.walk(path) #生成器,里面包含三个东西:根目录,根目录下的目录和文件;生成器只能用list读取
# print(list(folder)) 输出[('C:/Users/Administrator/Desktop/数据文件', [], ['data01.xlsx', 'data02.xlsx', 'data03.xlsx'])]
files = list(folder)[0][2] #选择文件名集合的list
data_all=[]
for file in files:
data=pd.read_excel(path+'/'+file)
data_all.append(data)
return(data_all)
data=f1()
data1=f1()[0]
data2=f1()[1]
data3=f1()[2]