Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python with pandas: file size (44546) not 512 + multiple of sector size (512)

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)
like image 246
xiehongguang Avatar asked Jan 26 '23 05:01

xiehongguang


1 Answers

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.

like image 108
Mad Physicist Avatar answered Jan 27 '23 20:01

Mad Physicist