The Python library pandas can read Excel spreadsheets and convert them to a pandas.DataFrame
with pandas.read_excel(file)
command. Under the hood, it uses xlrd library which does not support ods files.
Is there an equivalent of pandas.read_excel
for ods files? If not, how can I do the same for an Open Document Formatted spreadsheet (ods file)? ODF is used by LibreOffice and OpenOffice.
I've had good luck with pandas read_clipboard. Selecting cells and then copy from excel or opendocument. In python run the following.
Pandas will do a good job based on the cells copied.
Another option: read-ods-with-odfpy. This module takes an OpenDocument Spreadsheet as input, and returns a list, out of which a DataFrame can be created.
If you only have a few .ods files to read, I would just open it in openoffice and save it as an excel file. If you have a lot of files, you could use the
unoconv
command in Linux to convert the .ods files to .xls programmatically (with bash)Then it's really easy to read it in with
pd.read_excel('filename.xls')
Based heavily on the answer by davidovitch (thank you), I have put together a package that reads in a .ods file and returns a DataFrame. It's not a full implementation in
pandas
itself, such as his PR, but it provides a simpleread_ods
function that does the job.You can install it with
pip install pandas_ods_reader
. It's also possible to specify whether the file contains a header row or not, and to specify custom column names.