Ahmed Selmi
Ahmed Selmi

Reputation: 65

issue with pandas when launching a python script

I'm using Jupyter Notebook to create a graph out of an xlsx file. the code works and the graph is shown correctly on Jupyter but when i try to launch the script from CLI i get this result :

λ python Untitled.py

Traceback (most recent call last):<br/> File "Untitled.py", line 25, in <module><br/> 
 df = pd.read_excel(workbook)<br/> File
 "C:\Python\lib\site-packages\pandas\util\_decorators.py", line 299, in
 wrapper<br/>   return func(*args, **kwargs)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 336, in
 read_excel<br/>   io = ExcelFile(io, storage_options=storage_options,
 engine=engine)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 1131, in
 __init__<br/>   self._reader = self._engines[engine](self._io, storage_options=storage_options)<br/> File
"C:\Python\lib\site-packages\pandas\io\excel\_xlrd.py", line 24, in
 __init__<br/>   import_optional_dependency("xlrd", extra=err_msg)<br/> File "C:\Python\lib\site-packages\pandas\compat\_optional.py", line
 109, in import_optional_dependency   raise ImportError(msg) from
 None<br/> ImportError: Missing optional dependency 'xlrd'. Install
 xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

The code is the following :

import pandas as pd
import matplotlib.pyplot as plt

workbook = "sample_scores.xlsx"

df = pd.read_excel(workbook)
print(df.head())

values = df[['Name','Test 1']]
print (values)

ax = values.plot.bar(x='Name', y='Test 1')
plt.show()

I installed pandas and matplotlib packages and also verified Python path and everything is set correctly but it seems I'm missing something?

Upvotes: 0

Views: 2426

Answers (1)

sunil ghimire
sunil ghimire

Reputation: 545

!pip install xlrd

Install xlrd module

Upvotes: 1

Related Questions