python - 熊猫和电子表格
问题描述
我正在使用 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
或等),然后使用 pandas 的(可悲read_excel()
的)功能和engine='odf'
选项。例如:
pd.read_excel('path_to_file.ods', engine='odf')
请参阅https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#opendocument-spreadsheets。
推荐阅读
- sql - 基于模式的 SQL 表
- javascript - 从 React App 中的 json 文件导入时损坏的徽标图像
- sql - 不能用于索引或统计信息或用作分区键
- android - 如何使用 cesium 和 geoserver 在 android 应用程序中显示 wms 层?
- r - R如何通过脚本检查某些加载的包是否根本没有使用
- android - 我的导航抽屉的 android studio 预览没有显示菜单图标
- unity3d - 发现多个文件具有操作系统独立路径“META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version”Unity 2019.3
- visual-studio-code - 用于任务输出的 vscode“lint ignore”(未内置于 vscode 中的语言 - tasks.json/settings.json?)
- python - 关于 Jenkins 登录
- node.js - 卡尔曼滤波器上的状态矩阵 Xk 与 ecuation 的大小不匹配