I know this type of question is asked all the time. But I am having trouble figuring out the best way to do this.
I wrote a script that reformats a single excel file using pandas. It works great.
Now I want to loop through multiple excel files, preform the same reformat, and place the newly reformatted data from each excel sheet at the bottom, one after another.
I believe the first step is to make a list of all excel files in the directory. There are so many different ways to do this so I am having trouble finding the best way.
Below is the code I currently using to import multiple .xlsx and create a list.
import os import glob os.chdir('C:\ExcelWorkbooksFolder') for FileList in glob.glob('*.xlsx'): print(FileList) I am not sure if the previous glob code actually created the list that I need.
Then I have trouble understanding where to go from there. The code below fails at pd.ExcelFile(File) I beleive I am missing something....
# create for loop for File in FileList: for x in File: # Import the excel file and call it xlsx_file xlsx_file = pd.ExcelFile(File) xlsx_file # View the excel files sheet names xlsx_file.sheet_names # Load the xlsx files Data sheet as a dataframe df = xlsx_file.parse('Data',header= None) # select important rows, df_NoHeader = df[4:] #then It does some more reformatting. ' Any help is greatly appreciated
Fileorfilefor any sort of variable names in python becuasefileis a builtin.