def get_all_excel(filepath):
all_files = os.listdir(filepath)
for each_file in all_files:
if each_file.split(".")[-1] == "xlsx":
all_file_path.append(os.path.join(filepath, each_file))
else:
new_path = os.path.join(filepath, each_file)
get_all_excel(new_path)
path = r'D:\LiCN\Desk\tables'
all_file_path= []
get_all_excel(path)
all_file_path
讀取數(shù)據(jù), 添加上級(jí)目錄文件名
for i in all_file_path:
single_data_frame = pd.read_excel(i)
single_data_frame['course'] = i.split('\\')[-2]
if i == all_file_path[0]:
all_data_frame = single_data_frame
else:
all_data_frame = pd.concat([all_data_frame, single_data_frame],ignore_index=True)
all_data_frame.head()