FileNotFoundError: [Errno 2] No such file or directory

Hi,

I am trying to import Excel file in Python using Pandas. I am working in Spyder.
Below code is copied from a website and edited to suit my requirement.

import pandas as pd
excel_file = ‘ExcelPandasPythonExample.xls’
MyVariable = pd.read_excel(excel_file)
MyVariable.head()

I am getting below error while trying this code. Please note, both the excel file and Python file are saved in the same folder.

FileNotFoundError: [Errno 2] No such file or directory: ‘ExcelPandasPythonExample.xls’

Can anyone please help me in this.

Hi,
It is working now. Thanks. Did below changes to the code.

import pandas as MyPandas
MyExcel = MyPandas.read_excel (r’\Dummy\Dummy\Dummy\Dummy\ExcelPandasPythonExample.xls’)
print (MyExcel)

However facing one issue here, my excel file has 25 columns but I can see only two columns are imported in Python. First and last. There are three dots between first and last column of the imported excel. I can see [1338 rows x 25 columns] at the end of imported file. Also only few rows are visible from the imported file.

Can anyone please help me understand how do I import entire worksheet.

The first problem was caused by invalid file path - your excel file was in a different directory, hence Dummy\Dummy helped.

I assume you’re printing the pandas dataframe to the console. If that’s the case, then the “three dots” are a way to show that data is there but the output cannot fit into the console.

Once you load the excel file, try printing specific column instead.

1 Like

Hi @pymc , thanks a lot for the help and sorry for late reply.
Yes, am printing pandas dataframe to console.

Have a nice day ahead. :slight_smile: