1

Hi I am new to the open source tech - I am using Anaconda3-5.1.0-Windows-x86_64 & Microsoft Excel 2016.The Excel reading operation using pandas throws error as File not found error for the below code.

import pandas as pd 
from pandas import ExcelWriter 
from pandas import ExcelFile 
path= "D:\sample.xlsx" 
print(path) 
df = pd.read_excel(path, sheet_name = 'Sheet1') 
print('Column headings:') 
print(df.columns) 

The error message is FileNotFoundError: [Errno 2] No such file or directory: 'D:\sample.xlsx'-

I was trying to read 'D:\sample.xlsx' but the function tries to open file as 'D:\sample.xlsx'.

Can anyone please advise on this issue or shall let me know any more details required.

2
  • Please format your code. Commented May 4, 2018 at 7:11
  • apologies I tried pressing Ctrl+K but the code was not highlighted. Commented May 4, 2018 at 7:46

1 Answer 1

2

Change

path= "D:\sample.xlsx"

to

path= r"D:\sample.xlsx" or path= "D:\\sample.xlsx"
Sign up to request clarification or add additional context in comments.

5 Comments

Have tried with path= "D:\\sample.xlsx" - Same Error as File not Found & with path= r"D:\sample.xlsx" error is with open(filename, "rb") as f: FileNotFoundError: [Errno 2] No such file or directory: 'D:\\\\sample.xlsx'
Additonal logs as <pre> <Code> File "d:\Profiles\kgowdama\AppData\Local\Continuum\anaconda3\lib\site-packages\xlrd_init_.py", line 116, in open_workbook with open(filename, "rb") as f:
Are you sure you have the file in D:\sample.xlsx ?
What error did you get when u used path= r"D:\sample.xlsx"
This is the Error when I used path= r"D:\sample.xlsx" Error Details File "d:\Profiles\kgowdama\AppData\Local\Continuum\anaconda3\lib\site-packages\xlrd_init_.py", line 116, in open_workbook with open(filename, "rb") as f: FileNotFoundError: [Errno 2] No such file or directory: 'D:\\sample.xlsx'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.