我想从文件夹read_excel并加载到数据库中,但 excel 每周都会刷新并更改名称(ReportWK01、ReportWK02,...(在该文件夹中(名称To_Load(中只有我需要的Excel。
我尝试指定路径,然后read_excel,但我不知道正确的语法。
path = rb'\csd-fileddbbssuuTo_Load'
results = os.path.join(path, rb"**.xlsx")
df = pd.read_excel(results, engine='python')
是写我
ValueError: Must explicitly set engine if not passing in buffer or path for io.
## can you try reading it based on most recent time stamp
import os
import glob
folder_path ='\csd-fileddbbssuuTo_Load'
# glob.glob returns all paths matching the pattern.
excel_files = list(glob.glob(os.path.join(folder_path, '*.xls*')))
mod_dates = [os.path.getmtime(f) for f in excel_files]
print(mod_dates)
# sort by mod_dates.
file_date = sorted(zip(excel_files, mod_dates),reverse=True)
print("*"*100)
print(file_date)
newest_file_path = file_date[0][0]
df = pd.read_excel(newest_file_path)