简体   繁体   中英

Reading excel file with pandas

I have tried to read an excel file using pandas however I haven't been able to. I am using python version 3.8 and still haven't been able to do it. I want to make the excel file a list in python and then use that list in an option box via tkinter. However without being able to read the file I cannot do this.

The code I'm using is:

import pandas as pd

df = pd.read_excel (r'downloads\Clients - Nybble HelpDesk.xlsx')
print (df)

The error I'm recieving is:

Traceback (most recent call last):
  File "C:\Users\Natasha\OneDrive - Nybble.co.uk LTD\Desktop\excel export.py", line 1, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

In the command line try pip install pandas to install pandas first. Then re-run your code.

Other installation information is available here: https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html

you can save time by downloading the anacondas distribution and use the spyder IDE. This will prevent the need to install pandas and will come with a whole host of useful packages that you will likely use in your day to day.

See the link: https://docs.anaconda.com/anaconda/navigator/tutorials/pandas/

First install pandas. If you are using python shell then, open command prompt and type pip install pandas . If you are using Anaconda then, open Conda Prompt and type conda install pandas . You have your pandas library installed now. Now for your code,

import pandas as pd
excel_file = 'filepath.xls'
df = pd.read_excel(excel_file)
print (df)

Now try it! and be sure to check the path of your file. Save the file in the same folder where you are saving the .py file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM