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.
Is there any way to read data into DataFrame by selecting specific range of rows using pandas?
You can set the header option to None to ignore header.
In order to export pandas DataFrame to CSV without index (no row indices) use param index=False and to ignore/remove header use header=False param on to_csv() method.
To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With