Pandas:始终选择 Excel 工作表中的第一个工作表/标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30477987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas: Always selecting the first sheet/tab in an Excel Sheet
提问by Meghdeep Ray
I know how to get the list of sheet names. The excel file I am using has multiple sheets. How do I select the first one sequentially ? I don't know the name of the sheet but I need to select the first one. How would I go about this ?
我知道如何获取工作表名称列表。我使用的 excel 文件有多个工作表。如何依次选择第一个?我不知道工作表的名称,但我需要选择第一个。我该怎么办?
回答by Meghdeep Ray
The first sheet is automatically selected when the Excel table is read into a dataframe.
当 Excel 表被读入数据框时,第一个工作表会自动选择。
To be explicit however, the command is :
然而,明确地说,命令是:
import pandas as pd
fd = 'file path'
data = pd.read_excel( fd, sheet_name=0 )
Use of 'sheetname' is deprecated. Please use sheet_name
不推荐使用“sheetname”。请使用 sheet_name
回答by RGH
Also this bug at the time of writing: https://github.com/pandas-dev/pandas/issues/17107
在撰写本文时也是这个错误:https: //github.com/pandas-dev/pandas/issues/17107
Use 'sheetname', not 'sheet_name'.
使用“sheetname”,而不是“sheet_name”。
回答by alec_djinn
Following the official documentationand as already suggested by EdChum, it's enough to use read_excell passing sheetname=N as argument. N=0 for the first sheet, N=1 for the second, N=2 for the third and so on..
按照官方文档和 EdChum 已经建议的那样,使用 read_excell 传递 sheetname=N 作为参数就足够了。第一张纸 N=0,第二张 N=1,第三张 N=2,依此类推。

