IOError: [Errno 22] 使用 pandas.read_excel 的无效模式 ('rb') [英] IOError: [Errno 22] invalid mode ('rb') using pandas.read_excel

查看:91
本文介绍了IOError: [Errno 22] 使用 pandas.read_excel 的无效模式 ('rb')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直遇到以下错误.你应该知道文件名是正确的,这个pandas方法适用于其他py文件,请帮忙!!!

I keep having the following error. you should know that file name is correct and this pandas method works in other py files, please help !!!!

tablecouleurs 是一个没有特定字符的 Excel 表格

the tablecouleurs is an excel table with no specific characters

import pandas as pd

colors=pd.read_excel('C:\Users\paul\tablecouleurs.xlsx', index_col=0, has_index_names=True)

和错误:

runfile('C:/Users/paul/Documents/colors.py',wdir='C:/Users/pauldufosse/Documents') 回溯(最近调用最后):

runfile('C:/Users/paul/Documents/colors.py', wdir='C:/Users/pauldufosse/Documents') Traceback (most recent call last):

文件",第 1 行,在runfile('C:/Users/paul/Documents/colors.py', wdir='C:/Users/pauldufosse/Documents')

File "", line 1, in runfile('C:/Users/paul/Documents/colors.py', wdir='C:/Users/pauldufosse/Documents')

文件C:\Users\paul\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第 685 行,在运行文件中execfile(文件名,命名空间)

File "C:\Users\paul\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace)

文件C:\Users\paul\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第 71 行,在 execfile 中exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:\Users\paul\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)

文件C:/Users/paul/Documents/colors.py",第 12 行,在颜色=pd.read_excel('C:\Users\pauldufosse\tablecouleurs.xlsx', index_col=0, has_index_names=True)

File "C:/Users/paul/Documents/colors.py", line 12, in colors=pd.read_excel('C:\Users\pauldufosse\tablecouleurs.xlsx', index_col=0, has_index_names=True)

文件C:\Users\paul\Anaconda\lib\site-packages\pandas\io\excel.py",第 151 行,在 read_excel 中返回 ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)

File "C:\Users\paul\Anaconda\lib\site-packages\pandas\io\excel.py", line 151, in read_excel return ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)

文件C:\Users\paul\Anaconda\lib\site-packages\pandas\io\excel.py",第 188 行,在 init 中self.book = xlrd.open_workbook(io)

File "C:\Users\paul\Anaconda\lib\site-packages\pandas\io\excel.py", line 188, in init self.book = xlrd.open_workbook(io)

文件C:\Users\paul\Anaconda\lib\site-packages\xlrd_init_.py",第 394 行,在 open_workbook 中f = 打开(文件名,rb")

File "C:\Users\paul\Anaconda\lib\site-packages\xlrd_init_.py", line 394, in open_workbook f = open(filename, "rb")

IOError: [Errno 22] 无效模式 ('rb') 或文件名:'C:\Users\paul\tablecouleurs.xlsx'

IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\Users\paul\tablecouleurs.xlsx'

推荐答案

遇到了同样的问题.你可以通过双重逃避你的路径来解决它.

Had the same problem. You can solve it by double escaping your path.

错误消息说:

IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\Users\pauldufosse\tablecouleurs.xlsx'

就去做:

foo = pd.ExcelFile('C:\\Users\\pauldufosse\\tablecouleurs.xlsx')

这对我有用

这篇关于IOError: [Errno 22] 使用 pandas.read_excel 的无效模式 ('rb')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆