0

I am using ubuntu and as a result unable to use ms excel.Anyways I have created a spread sheet and I wish to make use of it in my python program. Following is the Python program.

import pandas as pd

df=pd.read_excel("/home/files/file1.ods")

df.head()

Traceback (most recent call last):
File "spreadsheet.py", line 2, in <module>
  df=pd.read_excel("/home/files/file1.ods")
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 163, in    read_excel
  io = ExcelFile(io, engine=engine)
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 187, in __init__
  import xlrd  # throw an ImportError if we need to
ImportError: No module named 'xlrd'

Does it mean that I have to use ms excel or is there an error in my understanding.Whatever be the case your help will be highly appreciated.

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
  • 1
    Did you try to pip install xlrd? – Idanmel Jun 09 '18 at 14:15
  • and if you're using something like pycharm, add xlrd to your project/environment – Jay Calamari Jun 09 '18 at 14:23
  • 1
    Installing xlrd won't be enough. The function is called read_excel, and it is meant to read excel files (xls and xlsx). If you want to read ods, you can [check here](https://stackoverflow.com/questions/17834995/how-to-convert-opendocument-spreadsheets-to-a-pandas-dataframe). Even better, just use csv, and the `read_csv` function. You can use libreoffice to save to csv, xls, or xlsx. – toto_tico Jun 09 '18 at 14:39
  • read_csv worked!!Thanks. – Tejus Shama Jun 10 '18 at 06:01

1 Answers1

1

In recent versions (since 0.25) of Pandas, this feature is provided.

Just install the odfpy package (with pip install odfpy or etc) and then use pandas' (sadly) read_excel() function with the engine='odf' option. For example:

pd.read_excel('path_to_file.ods', engine='odf')

See https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#opendocument-spreadsheets.

CPBL
  • 3,783
  • 4
  • 34
  • 44