Good day everyone.
My problem is: I can't get rows (data) between several rows.
I've got One excel book with 21 sheets. Every table on every sheet with some different changes. Tables haven't heads (people who made it - are idiots). But there are same values in first and second columns in tables. So, i get their indexes, but how to get rows between them?
import pandas as pd
file_path = r"./files/menu.xlsx"
df = pd.read_excel(file_path)
xl = pd.ExcelFile(file_path).sheet_names
breakfast = df.loc[df['Unnamed: 0'] == 'breakfast'].index[0] # index is "5"
dinner = df.loc[df['Unnamed: 0'] == 'dinner'].index[0] # index is "14"
heads = df.iloc[[int(breakfast) - 1]]
You can use the range start:end
in the iloc()
operation to specify start and end indexes. Remember that the start index is included in the result while the end index is excluded:
rows_between = df.iloc[int(breakfast)+1:int(dinner)]
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