I am using Python on Visual Studio Code to import an excel file but I am getting an import error

Question:

I want to read the data on an excel file within a F drive. I am using python on Visual Studio Code to try achieve this however I am getting an error as seen in the pictures below. I installed pandas but I still get an error. How can I fix this issue?

Coding Error

Installed Pandas Library

I tried closing and opening visual studio. I tried uninstalling and reinstalling pandas.

Python on Computer

Asked By: idkyet123

||

Answers:

You should try to open terminal in VS Code, and run pip freeze (and pip3 freeze). Check if you find pandas in the results, it won’t. That must be because you’d have multiple installations of Python on your system. You may, –

  1. Get rid of all but one Python installation.
  2. Install pandas on the VS Code installed python instance.
  3. Configure the same installation of python that is referenced by your command prompt.
Answered By: Jahnavee

To read an Excel file with Python, you need to install the pandas library. To install pandas, open the command line or terminal and type:

pip install pandas

Once pandas is installed, you can read an Excel file like this:

import pandas as pd

df = pd.read_excel(‘file_name.xlsx’)

print(df)

You should also make sure that the file path is correct and that you have the correct permissions to access the file.
If you are still having issues, try using the absolute file path instead of a relative file path.

Answered By: OTMANʏ EL
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.