Pandas Library won't find a specific excel file

Hello I’ve been trying to use the Pandas library to import excel files into my program and plot them with the seaborn library along with a few other libraries. Here’s my code:

import seaborn as sns
import pandas as pd

pd.read_excel('sales.xlsx')

I’m unable to import the file but it has just a few labels and a lot of numbers and I’m sure it saved to my downloads so I’m not really sure how to fix this. I’ve also tried to do it with a csv file but it also didn’t work.

As you’re giving the filename as just 'sales.xlsx', it’ll look in the current working folder, wherever that happens to be. It’s generally better to work with complete paths.

Okay.

Why do you expect the program to look in that folder for the file, out of all the other possible folders on your computer?

Or else, what exactly is your understanding of folders and paths? When you say “it saved to my downloads”, exactly what do you think that means - where do you think “my downloads” is?

It doesn’t ask for a file path
and I’m not that sure which file folder it looks into

First make sure you have openpyxl installed:

conda install openpyxl   # or pip install openpyxl if you're not using conda

Three alternative ways:

(1) Replace ‘sales.xlsx’ by the full path to the Excel file. If the file is located in Downloads on a Mac, this is ‘/Users/Downloads/{your_user_name}/sales.xlsx’.

(2) Alternatively:

from pathlib import Path
path = Path("~/Downloads/sales.xlsx")
df = pd.read_excel(path)
df

(3) Or copy the Excel file to the current directory (the directory in which you are starting python).
After copying the file over, run your original code.

I’ll test it out

the alternate way is still saying that it’s not working and it can’t find the files o I’m going to try the regular way

The first solution also doesn’t work…

As Karl suggested, you need to locate that file first. If the path lib solution did not work (or any of the others), that means that file is not in your Downloads folder. You may also want to check that you don’t have spaces or so in the file name.
First locate the file outside of python: What is the absolute path. Then use that.

okay I’ll remove it to the downloads file and see if that works

it is definetly in the downloads folder

do you know how to copy the absolute file path?

What is? If you go to the command line and type in

ls ~/Downloads/sales.xlsx

is it found?

I’ll check\

NO it is unable to find the file

So, it is not in the Downloads folder. Find out first what the exact name and path of the file is. Then you can use that.

Exactly what steps did you take, in order to figure this out? What do you think “the downloads folder” means, exactly? According to your understanding, exactly how did the file get there? According to your understanding, what is a folder?

1 Like

I did the command prompt message to find hte file, The downloads file is a place that stores everything you download, I pressed save to downloads in excel, a folder is a place that is designated for something to be there

I’m going to put the file into the documents folder and see if it works then

doesn’t work…