import pandas as pd
from glob import glob
fn ="xxx.xlsx"
df = pd.read_excel(fn,sheet_name="表2-1-1")
合并多个Excel或者多个Sheet
df = pd.DataFrame()# the glob module is used to retrieve files/pathnames matching a specified pattern
dir_filenames =sorted(glob('./*.xlsx'))# all excel files from current directoryfor dir_file in dir_filenames:
dict_xlsx = pd.read_excel(dir_file, sheet_name=None)
workbook = pd.concat([v_df.assign(Sheet = k)for k,v_df in dict_xlsx.items()], ignore_index=True)
df = pd.concat([df,workbook],ignore_index=True)print(f'shape of merged files:{df.shape}')