Published
- 1 min read
Appending pandas dataframes generated in a for loop
The solution for this is noted below
Appending pandas dataframes generated in a for loop
Solution
appended_data = []
for infile in glob.glob("*.xlsx"):
data = pandas.read_excel(infile)
# store DataFrame in list
appended_data.append(data)
# see pd.concat documentation for more info
appended_data = pd.concat(appended_data)
# write DataFrame to an excel sheet
appended_data.to_excel('appended.xlsx')
Try other methods by searching on the site. That is if this doesn’t work