【发布时间】:2018-06-09 14:08:38
【问题描述】:
我正在使用 ubuntu,因此无法使用 ms excel。无论如何我已经创建了一个电子表格,我希望在我的 python 程序中使用它。 以下是 Python 程序。
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'
这是否意味着我必须使用 ms excel 或者我的理解有误。无论如何,您的帮助将不胜感激。
【问题讨论】:
-
你试过 pip install xlrd 吗?
-
如果您使用的是 pycharm 之类的东西,请将 xlrd 添加到您的项目/环境中
-
安装 xlrd 是不够的。该函数名为 read_excel,用于读取 excel 文件(xls 和 xlsx)。想看ods的可以check here。更好的是,只需使用 csv 和
read_csv函数。您可以使用 libreoffice 保存到 csv、xls 或 xlsx。 -
read_csv 工作!!谢谢。
标签: python python-3.x pandas