FileNotFoundError: [Errno 2] No such file or directory Pandas

Question:

I am trying to read my excel file with pd.read_excel in python.
But ı am get this error message = FileNotFoundError: [Errno 2] No such file or directory

I put my excel file same place with my python file.
pic1 pic2

Asked By: Selman

||

Answers:

I think you can modify the code by writing it in this way:

pd.read_excel("./<file name>")
Answered By: Marya

You can use full path this way to read the excel file. And also add r prefix before the file path so backslash will be treated as literal character

pd.read_excel(r"C:UsersselmanPycharmProjectsselman_learningbisiklet_fiyatlari.xlsx")
Answered By: gajendragarg

I think you need to put file object and not only the path of the file.
Try to use:

with open("<path to your file>", encoding = 'utf-8') as f:
     pandas.read_excel(f)
Answered By: ste1213
import pandas as pd
path = 'absolute_path/records.xlsx' #eg. C:\Projects\readexcel\file\records.xlsx
df = pd.read_excel(path)

Do the above

Answered By: JaySean

Providing the absolute path to the .xlsx file worked for me. For situations where you cannot anticipate what the absolute path will be, try the following:

import os.path

pd.read_excel(io=os.path.abspath('path\to\excel_file.xlsx'))

‘pathtoexcel_file.xlsx’ should be the relative path to the .xlsx from the project root.

Credit to this answer to a similar question.

Answered By: Eystein Thanisch
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.