如何跳过 pandas 数据框中的页眉和页脚数据? [英] How to skip header and footer data in pandas dataframe?

查看:75
本文介绍了如何跳过 pandas 数据框中的页眉和页脚数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel文件的前 15行作为标题数据". 在 235行之后,是页脚数据". 我需要读取这些页眉和页脚数据之间的数据.

I have first 15 rows of a excel file as "Header data". and after 235 rows, "Footer data". I need to read data in between these header and footer data.

是否可以通过使用熊猫选择特定范围的行来将数据读取到DataFrame中?

Is there any way to read data into DataFrame by selecting specific range of rows using pandas?

推荐答案

演示:

xl = pd.ExcelFile(filepath)

# parsing first (index: 0) sheet
total_rows = xl.book.sheet_by_index(0).nrows

skiprows = 15
nrows = 235 - 15

# calc number of footer rows
# (-1) - for the header row
skipfooter = total_rows - nrows - skiprows - 1

df = xl.parse(0, skiprows=skiprows, skipfooter=skipfooter)

这篇关于如何跳过 pandas 数据框中的页眉和页脚数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆