如何使用pandas.read\u excel重命名索引列

2024-04-23 08:20:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用read_excel()读取excel文件.xls,我需要跳过前16行,跳过页脚38行,只使用2,3,4,5列,将第二列设置为索引列,将第16行设置为标题行,并重命名标题行。但是朱庇特回来了

excel_file = 'Filename.xls'

df = pd.read_excel(excel_file, header = 0, skiprows = 16, skip_footer = 38, usecols = [2,3,4,5], names = ['Name1', 'Name2', 'Name3', 'Name4'], index_col = 0)

df

我尝试了without index_col=0它可以工作,但是设置了默认索引列,我不需要默认索引列,我需要我的带有“Name1”的列作为索引列


Tags: 文件标题dfreadindexcolfilenamexls