如何用Python从我的XLS文件中读取特定的工作表

编程入门 行业动态 更新时间:2024-10-10 05:23:16
本文介绍了如何用Python从我的XLS文件中读取特定的工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

到目前为止,我可以阅读Excel文件的所有工作表。

e.msgbox("select Excel File") updated_deleted_xls = e.fileopenbox() book = xlrd.open_workbook(updated_deleted_xls, formatting_info=True) openfile = e.fileopenbox() for sheet in book.sheets(): for row in range(sheet.nrows): for col in range(sheet.ncols): thecell = sheet.cell(row, 0) xfx = sheet.cell_xf_index(row, 0) xf = book.xf_list[xfx] 推荐答案

如果从桌面或命令行打开编辑器,则在尝试读取文件时必须指定文件路径:

import pandas as pd df = pd.read_excel(r'File path', sheet_name='Sheet name')

或者,如果您在文件目录中打开您的编辑器,则可以使用Panda库直接读取

import pandas as pd df = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='Title Sheet') df1 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx',sheet_name='Transactions') df2 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='NewCustomerList') df3 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerDemographic') df4 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerAddress')

更多推荐

如何用Python从我的XLS文件中读取特定的工作表

本文发布于:2023-10-31 10:12:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   文件   工作   XLS   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!