问题描述:

I'm trying to import some data from an excel file which has a very large footer.

When i put skip_footer=[245:] it tells me that : is invlaid syntax.

How can i cut out the footer from row (0-indexed) 245 to the end of the footer?

I dont want to manually list it [245, 246, 247 ...] as that would take ages.

Many thanks

网友答案:

skip_footer requires an integer. To skip from line 245 onward, unfortunately you need to know the number of lines in the file.

import openpyxl
wb = openpyxl.load_workbook('your_file.xlsx')
sheet = wb.worksheets[0]
last_row = wb.max_row

pd.read_excel('your_file.xlsx', skip_footer=last_row-245)

In this case footer just refers to excess data at the end of the file you don't want to read, not the special Header / Footer feature in Excel, so the above will skip lines 245 onward.

相关阅读:
Top