[英]Pandas and Spreadsheet
我正在使用 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 或者我的理解有誤。無論如何,您的幫助將不勝感激。
在 Pandas 的最新版本(自 0.25 起)中,提供了此功能。
只需安裝odfpy
包(使用pip install odfpy
等),然后使用帶有engine='odf'
選項的 pandas'(可悲的是) read_excel()
函數。 例如:
pd.read_excel('path_to_file.ods', engine='odf')
請參閱https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#opendocument-spreadsheets 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.