Bad magic number for central directory

ben犇發表於2024-03-10

Bad magic number for central directory

執行程式碼輸出如下bug:

  File "/home/a/Prediction/Predict_Models.py", line 153, in save_results
    existing_df = pd.read_excel(output_file_path)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anaconda3/envs/python310/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 495, in read_excel
    io = ExcelFile(
         ^^^^^^^^^^
  File "/home/anaconda3/envs/python310/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 1550, in __init__
    ext = inspect_excel_format(
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/anaconda3/envs/python310/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 1419, in inspect_excel_format
    with zipfile.ZipFile(stream) as zf:
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anaconda3/envs/python310/lib/python3.11/zipfile.py", line 1304, in __init__
    self._RealGetContents()
  File "/home/anaconda3/envs/python310/lib/python3.11/zipfile.py", line 1401, in _RealGetContents
    raise BadZipFile("Bad magic number for central directory")
zipfile.BadZipFile: Bad magic number for central directory

背景:

嘗試把多個程序的執行結果寫入到同一個excel表格的不同sheet中。

解決方法:

寫如不同的excel表格中。

相關文章