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.
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?
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’.
(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.
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.
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?
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