Bad magic number for central directory

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表格中。

posted @ 2024-03-10 16:49  ben犇  阅读(218)  评论(0编辑  收藏  举报