How to skip header and footer data in pandas dataframe?

前端 未结 4 956
孤街浪徒
孤街浪徒 2021-01-04 10:44

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 da

4条回答
  •  独厮守ぢ
    2021-01-04 11:15

    Demo:

    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)
    

提交回复
热议问题