如何解决使用read_excel读取一个或另一个特定工作表名称的pythonic方法是什么
我有一个项目,我正在阅读和绘制公司财务信息,这些公司的财务信息已输入并以.ods格式电子表格存储。使用pd.read_excel()中的odfreader将数据读入熊猫数据框。
我正在扩展输入电子表格的详细信息的范围和数量,因此有2个不同的版本;原始的和新的。
原始文件的工作表仅包含公司财务信息的基本摘要,而新版本的工作表中包含的数据量有所增加。它们的名称不同,因此我一眼就知道它们将包含哪些信息以及是否需要更新。
我当前正在使用以下代码查看摘要表的哪个版本,并加载确实存在的版本。
try:
financial_summary_sheet = pd.read_excel(financial_history_file,'Financial Summary',header=1,engine='odf') # new format
except:
financial_summary_sheet = pd.read_excel(financial_history_file,'Base Financials',engine='odf') # old format
它可以工作,但是是否可以在if / else语句中做到这一点?
if financial_history_file.is_file(): # Load the financial history file for the security if it exists
# if it does exist,read file and do many things with the data...
或检查工作表中是否存在一列;
if 'Notes' not in financial_summary_sheet: # check if Notes column exists in sheet
# if it doesn't,make notes column to explain the things of many...
我找不到使用if / else语句确定工作表名称是否存在的类似方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。