Reading data from excel after locating some expression


I am trying to read data from excel file based on a particular pattern.
I want my Dataframe to be created from the row where Account Number is present. It should be making that row a header and data afterwards.
How can i achieve the same without reading the file twice.
I am able to achieve the same by using below code, but it reads the file twice. Thus, becomes time consuming.

    data = pd.read_excel(r'C:\Users\Dell\Desktop\data.xlsx')
    num = 0
    for index,row in data.iterrows():
        if 'Account Number' in row.values:
            num = index
    data = pd.read_excel(r'C:\Users\Dell\Desktop\data.xlsx',header=num+1)
    data = data.dropna(axis=0, how='all')

data.xlsx (8.4 KB)

1 Like

Hi @rhlkhandelwal19:

Please provide a question link as per these guidelines so that we can better assist you if your question is from one of our courses, otherwise kindly change the tag to Non-DQ Courses. Additionally, your file was not uploaded properly so you might want to look into that.