问题
After read excel file with pandas, gets the follow warning:
key code:
pd_obj = pd.read_excel("flie.xls", dtype=str, usecols=usecols, skiprows=3)
for idx, row in pd_obj.iterrows():
json_tmpl = copy.deepcopy(self.details)
json_tmpl["nameInBank"] = row["nameInBank"]
json_tmpl["totalBala"] = row["totalBala"].replace(",", '')
# parse pdf file
status = self._get_banksplip_json(json_tmpl["bankReceipts"], row)
json_buf.append(copy.deepcopy(json_tmpl))
warning info :
WARNING *** file size (48130) not 512 + multiple of sector size (512)
WARNING *** file size (44546) not 512 + multiple of sector size (512)
回答1:
This appears to be a normal warning from the underlying XLRD library, and it seems safe to ignore. A pandas issue (#16620) was opened and closed without a conclusive resolution. However, the discussion did provide an alternative that would allow you to suppress the warnings:
from os import devnull
import pandas as pd
import xlrd
wb = xlrd.open_workbook('file.xls', logfile=open(devnull, 'w'))
pd_obj = pd.read_excel(wb, dtype=str, usecols=usecols, skiprows=3, engine='xlrd')
You can read a more detailed analysis of the actual cause of the error on the forum here: https://groups.google.com/forum/m/#!topic/python-excel/6Lue-1mTPSM
Moral of the story: whenever you get a warning you aren't sure about, you should search for the keywords that appear (discard any specific parts like file sizes or local paths). This answer is based on the first two results to show up on Google.
来源:https://stackoverflow.com/questions/60749802/python-with-pandas-file-size-44546-not-512-multiple-of-sector-size-512