'Appending Excel files to Python DataFrame

The below code goes through the excel files in the Regis folder and appends them into a new DataFrame. I need to make the following changes to the code:

  1. The data starts in column 7 so I do not need to append the first 6 rows of each Excel file
  2. Each Excel Sheet has a date at the end of the file name e.g. "Regis 30012022" The last 8 digits are the date (European format) and I would like to add a column so that I know which date the data refers to. This date should be added to column A.
import pandas as pd
import glob
  
# path of the folder
path = r'Regis'

# reading excel files
filenames = glob.glob(path + "\*.xlsx")
print('File names:', filenames)
  
# initializing empty data frame
finalexcelsheet = pd.DataFrame()
  
# interating through all excel files
for file in filenames:
  
    # combining multiple excel worksheets into single data frames
    df = pd.concat(pd.read_excel(file, sheet_name=None), ignore_index=True, sort=False)
  
    # appending excel files one by one
    finalexcelsheet = finalexcelsheet.append(df, ignore_index=True)
  
finalexcelsheet.to_excel(r'Final.xlsx', index=False)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source