0
votes

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 !!!!

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)

and error:

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

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

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

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

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)

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)

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

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

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

2
Have you tried with forward slashes? You have a \t (..sse\tabl..) in that filename (tab character) so maybe that's why it's failing?johnharris85

2 Answers

1
votes

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

The error messages says:

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

Just do:

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

This worked for me

0
votes
open_workbook f = open(filename, 'rb')

If you check Python library you will see you have to use single quote instead of double quote.