Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88050

Trying to make a program that takes multiple spreadsheets from multiple workbooks and merge them with there equivalent in the other workbooks

$
0
0
import pandas as pd
 from os import listdir

 from os.path import isfile , join

folder = "c:/sheets"

excel_names = [f for f in listdir(folder) if isfile(join(folder, f))]
 print(excel_names)
 excel_files = []
for item in excel_names:
 item = folder + item excel_files.append(item)
 # read them in
excels = [pd.ExcelFile(name) for name in excel_files]
# turn them into dataframes
 frames = [x.parse(x.sheet_names[0], header=None, index_col=None) 
for x in excels]
# delete the first row for all frames except the first
#  i.e. remove the header row -- assumes it's the first

 frames[1:] = [df[1:] for df in frames[1:]]
# concatenate them..
 combined = pd.concat(frames) combined.to_excel(folder+"/combined.xlsx", header=False, index=False)

This is the code I wrote so far but it seems to work for one sheet only in multiple workbook. What should I do?


Viewing all articles
Browse latest Browse all 88050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>