pythonexcelpandasdataframe

Skipping last 4 rows and the first 16 rows when reading excel file into Python Pandas


I know how to skip the first 16 rows of a excel file when reading into Pandas like

df = pd.read_excel(file, engine='openpyxl', skiprows=16, usecols = "B:F")

But how can I skip the last 4 rows and the first 16 rows?

Any suggestions?


Solution

  • You can try to use the skipfooter parameter together with skiprows, as follows:

    df = pd.read_excel(file, engine='openpyxl', skiprows=16, skipfooter=4, usecols = "B:F")
    

    skipfooter int, default 0
    Rows at the end to skip (0-indexed).