如何解决Excel sheet表读取问题
文章编号:Python学【2020】010号
日期:2019-3-1
文章为日常学习记录,以备温习使用,同时作为像我一样的新人学习使用,内容属于学习记录,版权归可能涉及相关方利益,如涉及版权请提示,本人参考后选择和评价是否应删除文章。以每天追无聊小说的心态,每天坚持学习码代码。
小编检索好长时间无法解决,读取Excel sheet表名时,无法按照panda指导文件实现。学习文章更新也停止,今天在实操训练中,检索相关指导文件顺利解决,现分享如下:
目标文件来自于英文网站,连接网址信息如下:
按照pandas指引读取Excel sheet表数据时,无论尝试按照sheet_name=index值,还是sheet2序次名称,sheet name,都无效的解决办法
原作者提出问题如下:
According to the doc, pandas.read_excel has a parameter sheet_name that allows specifying which sheet is read. But when I am trying to read the second sheet from an excel file, no matter how I set the parameter (sheet_name = 1, sheet_name = ‘Sheet2’), the dataframe always shows the first sheet, and passing a list of indices (sheet_name = [0, 1]) does not return a dictionary of dataframes but still the first sheet. What might be the problem here?
我的目标要求是读取“资产表2”的信息,执行如下代码,实现读取默认的sheet1的信息
sheet_name='利润表'
df1 = pd.read_excel('公司1.xls',sheet_name=sheet_name)
df1
df1 = pd.read_excel('公司1.xls',sheet_name='利润表')
df1
结果如图:
正解:
按照解答文件,由于版本原因,调用ExcelFile函数,执行后实现我的目标要求,读取到指定文件数据
xls = pd.ExcelFile('公司1.xls')
df1 = pd.read_excel(xls, '利润表')
df1