我不知道为什么会出现这样的错误,虽然有时我的代码工作得很好!但我不知道为什么会出现这样的错误。
Excel file format cannot be determined, you must specify an engine manually.
Here below is my code with steps:
1- list of columns of customers Id:
customer_id = ["ID","customer_id","consumer_number","cus_id","client_ID"]
2- 找到一个文件夹中的所有xlsx文件并读取它们的代码。
l = [] #use a list and concat later, faster than append in the loop
for f in glob.glob("./*.xlsx"):
df = pd.read_excel(f).reindex(columns=customer_id).dropna(how='all', axis=1)
df.columns = ["ID"] # to have only one column once concat
l.append(df)
all_data = pd.concat(l, ignore_index=True) # concat all data
我添加了发动机openpyxl
。
df = pd.read_excel(f, engine="openpyxl").reindex(columns = customer_id).dropna(how='all', axis=1)
现在我得到了一个不同的错误。
BadZipFile: File is not a zip file
pandas版本:1.3.0
python版本: python3.9
操作系统: MacOS
是否有更好的方法来读取一个文件夹中的所有xlsx文件?