[Python] Bad CRC-32 for file

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to read a xlsx table with python, but always got a "Bad CRC-32 for file". However I can open the files with excel without breakdown. How can I fix it? Here is the code:

    import pandas as pd
    import numpy as np

    # Step 1: Load data
    file_path = 'summerOly_athletes_after1992_wr.xlsx'
    raw_data = pd.read_excel(file_path, engine='openpyxl')


    The error messages are as follow:

    Traceback (most recent call last):
    File "/mnt/c/Users/DELL/Desktop/MCM/prob1_another.py", line 10, in <module>
    raw_data = pd.read_excel(file_path, engine='openpyxl')
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/site-packages/pandas/io/excel/_base.py", line 508, in read_excel
    data = io.parse(
    ^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/site-packages/pandas/io/excel/_base.py", line 1616, in parse
    return self._reader.parse(
    ^^^^^^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/site-packages/pandas/io/excel/_base.py", line 778, in parse
    data = self.get_sheet_data(sheet, file_rows_needed)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/site-packages/pandas/io/excel/_openpyxl.py", line 615, in get_sheet_data
    for row_number, row in enumerate(sheet.rows):
    ^^^^^^^^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/site-packages/openpyxl/worksheet/_read_only.py", line 85, in _cells_by_row
    for idx, row in parser.parse():
    ^^^^^^^^^^^^^^
    File "openpyxl/worksheet/_reader.py", line 156, in parse
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/xml/etree/ElementTree.py", line 1238, in iterator
    data = source.read(16 * 1024)
    ^^^^^^^^^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/zipfile/__init__.py", line 989, in read
    data = self._read1(n)
    ^^^^^^^^^^^^^^
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/zipfile/__init__.py", line 1079, in _read1
    self._update_crc(data)
    File "/home/ziyuliu258/anaconda3/envs/tsfl/lib/python3.12/zipfile/__init__.py", line 1007, in _update_crc
    raise BadZipFile("Bad CRC-32 for file %r" % self.name)
    zipfile.BadZipFile: Bad CRC-32 for file 'xl/worksheets/sheet1.xml'


    I tried to use the engine=openpyxl but got the same error. And I just began to use python a few days ago. I can easily get lost when coping with such code segments.

    Continue reading...

Compartilhe esta Página