Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python XLRDError:不支持的格式或损坏的文件:预期的BOF记录;找到b'\x00\x00\x00\x01Bud1';_Python_Python 3.x_Pandas_Macos_Xlrd - Fatal编程技术网

Python XLRDError:不支持的格式或损坏的文件:预期的BOF记录;找到b'\x00\x00\x00\x01Bud1';

Python XLRDError:不支持的格式或损坏的文件:预期的BOF记录;找到b'\x00\x00\x00\x01Bud1';,python,python-3.x,pandas,macos,xlrd,Python,Python 3.x,Pandas,Macos,Xlrd,我试图合并一些excel文件,并得到以下错误 注意:这段代码在windows中运行良好,我正试图在mac上运行同样的代码,我收到了这个错误 代码: import pandas as pd import os all_data=pd.DataFrame() <br/> temp1=pd.DataFrame()<br/> temp2=pd.DataFrame() FL=os.listdir("Files/") for i in FL:<br/> t

我试图合并一些excel文件,并得到以下错误

注意:这段代码在windows中运行良好,我正试图在mac上运行同样的代码,我收到了这个错误

代码:

import pandas as pd
import os


all_data=pd.DataFrame() <br/>
temp1=pd.DataFrame()<br/>
temp2=pd.DataFrame()

FL=os.listdir("Files/")

for i in FL:<br/>
    temp1=pd.read_excel("Files/"+i)<br/>
    print("Reading file "+ i)<br/>
    temp1.loc[:, "Sub Query"] = i[0:i.find(".")]<br/>
    print("working on file "+ i)<br/>
    temp2 = pd.concat([temp2,temp1], sort=False)<br/>
    print("file "+ i +" is over, moving on...")<br/>

writer = pd.ExcelWriter("output/Mastersheet.xlsx", engine='xlsxwriter', options={'strings_to_urls': False})<br/>
temp2.to_excel(writer, index=False)<br/>
writer.close()<br/>


**Error:**

 File "<ipython-input-9-1e7da69236eb>", line 1, in <module>
    runfile('/Users/simplify360/Desktop/TVS/Consolidate/consolidate.py', wdir='/Users/simplify360/Desktop/TVS/Consolidate')

  File "/Applications/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "/Applications/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/simplify360/Desktop/TVS/Consolidate/consolidate.py", line 19, in <module>
    temp1=pd.read_excel("Files/"+i)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/util/_decorators.py", line 208, in wrapper
    return func(*args, **kwargs)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 310, in read_excel
    io = ExcelFile(io, engine=engine)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 819, in __init__
    self._reader = self._engines[engine](self._io)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
    super().__init__(filepath_or_buffer)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 359, in __init__
    self.book = self.load_workbook(filepath_or_buffer)

  File "/Applications/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py", line 36, in load_workbook
    return open_workbook(filepath_or_buffer)

  File "/Applications/anaconda3/lib/python3.7/site-packages/xlrd/__init__.py", line 157, in open_workbook
    ragged_rows=ragged_rows,

  File "/Applications/anaconda3/lib/python3.7/site-packages/xlrd/book.py", line 92, in open_workbook_xls
    biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)

  File "/Applications/anaconda3/lib/python3.7/site-packages/xlrd/book.py", line 1278, in getbof
    bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])

  File "/Applications/anaconda3/lib/python3.7/site-packages/xlrd/book.py", line 1272, in bof_error
    raise XLRDError('Unsupported format, or corrupt file: ' + msg)

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\x00\x00\x00\x01Bud1'
将熊猫作为pd导入
导入操作系统
all_data=pd.DataFrame()
temp1=pd.DataFrame()
temp2=pd.DataFrame() FL=os.listdir(“文件/”) 对于FL中的i:
temp1=pd.read_excel(“文件/”+i)
打印(“读取文件”+i)
temp1.loc[:,“子查询”]=i[0:i.find(“.”)]
打印(“处理文件”+i)
temp2=pd.concat([temp2,temp1],sort=False)
打印(“文件“+i+”已结束,继续…”)
writer=pd.ExcelWriter(“output/Mastersheet.xlsx”,engine='xlsxwriter',options={'strings'u to'u url':False})
temp2.to_excel(writer,index=False)
writer.close()
**错误:** 文件“”,第1行,在 运行文件('/Users/simpled360/Desktop/TVS/Consolidate/Consolidate.py',wdir='/Users/simpled360/Desktop/TVS/Consolidate') 文件“/Applications/anaconda3/lib/python3.7/site packages/spyder\u kernels/customize/spydercurustomize.py”,第827行,在runfile中 execfile(文件名、命名空间) 文件“/Applications/anaconda3/lib/python3.7/site packages/spyder_kernels/customize/spydercurustomize.py”,第110行,在execfile中 exec(编译(f.read(),文件名,'exec'),命名空间) 文件“/Users/simplify360/Desktop/TVS/Consolidate/Consolidate.py”,第19行,在 temp1=pd.read_excel(“文件/”+i) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/util/_decorators.py”,第208行,在包装器中 返回函数(*args,**kwargs) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/io/excel/_base.py”,第310行,以只读excel格式 io=ExcelFile(io,engine=engine) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/io/excel/_base.py”,第819行,在__ self.\u reader=self.\u引擎[引擎](self.\u io) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/io/excel/_xlrd.py”,第21行,在__ super().\uuuu init\uuuu(文件路径或缓冲区) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/io/excel/_base.py”,第359行,在__ self.book=self.load\u工作簿(文件路径或缓冲区) 文件“/Applications/anaconda3/lib/python3.7/site packages/pandas/io/excel/_xlrd.py”,第36行,加载工作簿 返回打开的\u工作簿(文件路径\u或\u缓冲区) 文件“/Applications/anaconda3/lib/python3.7/site packages/xlrd/_init__.py”,第157行,在open_工作簿中 参差不齐的行=参差不齐的行, 文件“/Applications/anaconda3/lib/python3.7/site packages/xlrd/book.py”,第92行,在open\u工作簿\u xls中 biff\u version=bk.getbof(XL\u工作簿\u全局) 文件“/Applications/anaconda3/lib/python3.7/site packages/xlrd/book.py”,第1278行,在getbof中 bof_错误('预期的bof记录;找到%r'%self.mem[savpos:savpos+8]) 文件“/Applications/anaconda3/lib/python3.7/site packages/xlrd/book.py”,第1272行,bof_错误 raise XLRDError('不支持的格式或损坏的文件:'+msg) XLRDError:不支持的格式或损坏的文件:预期的BOF记录;找到b'\x00\x00\x00\x01Bud1'

我尝试过不同的方法,比如从excel文件中删除几个字段,重命名excel文件,但仍然不起作用。请帮忙!谢谢

我也遇到了同样的问题,我刚刚解决了。问题是在Mac上的每个目录中都有一个名为“.DS_Store”的隐藏文件。尝试更改此代码块:

for i in FL:<br/>
    temp1=pd.read_excel("Files/"+i)<br/>
    print("Reading file "+ i)<br/>
    temp1.loc[:, "Sub Query"] = i[0:i.find(".")]<br/>
    print("working on file "+ i)<br/>
    temp2 = pd.concat([temp2,temp1], sort=False)<br/>
    print("file "+ i +" is over, moving on...")<br/>
FL中的i的

temp1=pd.read_excel(“文件/”+i)
打印(“读取文件”+i)
temp1.loc[:,“子查询”]=i[0:i.find(“.”)]
打印(“处理文件”+i)
temp2=pd.concat([temp2,temp1],sort=False)
打印(“文件“+i+”已结束,继续…”)
为此:

for i in FL:<br/>
    if(i != '.DS_Store'):
        temp1=pd.read_excel("Files/"+i)<br/>
        print("Reading file "+ i)<br/>
        temp1.loc[:, "Sub Query"] = i[0:i.find(".")]<br/>
        print("working on file "+ i)<br/>
        temp2 = pd.concat([temp2,temp1], sort=False)<br/>
        print("file "+ i +" is over, moving on...")<br/>
FL中的i的

如果(i!='.DS_Store'): temp1=pd.read_excel(“文件/”+i)
打印(“读取文件”+i)
temp1.loc[:,“子查询”]=i[0:i.find(“.”)]
打印(“处理文件”+i)
temp2=pd.concat([temp2,temp1],sort=False)
打印(“文件“+i+”已结束,继续…”)

我也遇到了同样的问题,我刚刚解决了它。问题是在Mac上的每个目录中都有一个名为“.DS_Store”的隐藏文件。尝试更改此代码块:

for i in FL:<br/>
    temp1=pd.read_excel("Files/"+i)<br/>
    print("Reading file "+ i)<br/>
    temp1.loc[:, "Sub Query"] = i[0:i.find(".")]<br/>
    print("working on file "+ i)<br/>
    temp2 = pd.concat([temp2,temp1], sort=False)<br/>
    print("file "+ i +" is over, moving on...")<br/>
FL中的i的

temp1=pd.read_excel(“文件/”+i)
打印(“读取文件”+i)
temp1.loc[:,“子查询”]=i[0:i.find(“.”)]
打印(“处理文件”+i)
temp2=pd.concat([temp2,temp1],sort=False)
打印(“文件“+i+”已结束,继续…”)
为此:

for i in FL:<br/>
    if(i != '.DS_Store'):
        temp1=pd.read_excel("Files/"+i)<br/>
        print("Reading file "+ i)<br/>
        temp1.loc[:, "Sub Query"] = i[0:i.find(".")]<br/>
        print("working on file "+ i)<br/>
        temp2 = pd.concat([temp2,temp1], sort=False)<br/>
        print("file "+ i +" is over, moving on...")<br/>
FL中的i的

如果(i!='.DS_Store'): temp1=pd.read_excel(“文件/”+i)
打印(“读取文件”+i)
temp1.loc[:,“子查询”]=i[0:i.find(“.”)]
打印(“处理文件”+i)
temp2=pd.concat([temp2,temp1],sort=False)
打印(“文件“+i+”已结束,继续…”)

Hey sai,你能做
print(FL)
并在这里发布输出吗?我感觉你试图用excel读取非excel文件,因此出现了错误。Hey sai,你能做
print(FL)
并在这里发布输出吗?我感觉你试图用excel读取非excel文件,因此出现了错误。