Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

It doesn't read the file

+1 vote
asked May 19 by Frank Chang (130 points)
excel_file = r"C:\Users\hea\Documents\Work\Test.xlsx". It has this error message.

I checked file path, name or extension and all seems fine. I loaded this code to ChatGPT and it says it is correct. So I don't know what's wrong. Can anyone please help?

[?2004l Traceback (most recent call last): File "/home/main.py", line 115, in <module> df = pd.read_excel(excel_file) File "/usr/lib/python3/dist-packages/pandas/util/_decorators.py", line 311, in wrapper return func(*args, **kwargs) File "/usr/lib/python3/dist-packages/pandas/io/excel/_base.py", line 364, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "/usr/lib/python3/dist-packages/pandas/io/excel/_base.py", line 1191, in __init__ ext = inspect_excel_format( File "/usr/lib/python3/dist-packages/pandas/io/excel/_base.py", line 1070, in inspect_excel_format with get_handle( File "/usr/lib/python3/dist-packages/pandas/io/common.py", line 711, in get_handle handle = open(handle, ioargs.mode) FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\hea\\Documents\\Work\\Test.xlsx' [?2004h

1 Answer

0 votes
answered May 20 by Peter Minarik (88,520 points)

If you read the error message, you'll see that the file does not exist, so you cannot open it, and that's why you get an error message.

 FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\hea\\Documents\\Work\\Test.xlsx'

Make sure there is a file on that path and you didn't make any typos.

Oh, and if you're trying to run the Python script in OnlineGDB, then you have to remember that all of this is running on a remote server. The server does not (nor should) have access to your local file system.

You can upload your file with the icons left of the big green RUN button and add them to your project. File extension .txt definitely works and OnlineGDB does not try to be smart and compile it. :)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.