I have a folder with 4 files, I want to concatenate the 2 first files into df1 and the 2 second files into df2
I found this method but actually it concatenates all of the files into one dataframe
fiels = #the path
df= pd.concat([pd.read_excel(fiel) for fiel in glob.glob(fiels "/*.xlsx")],ignore_index=True)
Any suggestions to do this please?
CodePudding user response:
IIUC select files by indexing - first 2 and all another like:
files = glob.glob(fiels "/*.xlsx")
df1 = pd.concat([pd.read_excel(fiel) for fiel in files[:2]],ignore_index=True)
df2 = pd.concat([pd.read_excel(fiel) for fiel in files[2:]],ignore_index=True)