[英]How to combine excel files with different folders
I am new to python, have got a task of combining the excel files.我是 python 的新手,我的任务是合并 excel 文件。 I have 100 folders, each folder have 2 sub folders and in each sub folder have 24 excel files.我有 100 个文件夹,每个文件夹有 2 个子文件夹,每个子文件夹中有 24 个 excel 文件。 now I have to find maximum value and minimum values of each and every 24 files and that value I have to concatenate with parent excel file (this one have to do for all 24 files).现在我必须找到每个 24 个文件的最大值和最小值,并且我必须将这个值与父 excel 文件连接(这个必须对所有 24 个文件做)。 then i have to concatenate all 24 files have to write on first column of excel file.然后我必须连接所有 24 个文件必须写入 excel 文件的第一列。 and this should be repeat for all the 100 folder, so finally i have to get single excel file with 100 column.这应该对所有 100 个文件夹重复,所以最后我必须得到一个包含 100 列的 excel 文件。 presently I am using manual method for every file and it is over writing is become complicated and time consuming please someone help me to get-out of that method目前我对每个文件都使用手动方法,并且过度写入变得复杂且耗时,请有人帮助我摆脱这种方法
data12 = pd.read_excel (r'C:\Users\Videos\1.xlsx')
A= max(data12)
C= min(data12)
frame_data= [data12, A, C]
result = pd.concat(frame_data)
result.to_excel("output1.xlsx", sheet_name='modify_data', index=False)
You can use python glob library to browse through all the files in all the folders.您可以使用 python glob 库来浏览所有文件夹中的所有文件。 You just need to pass the name of master folder.您只需要传递主文件夹的名称。 and then use one loop to read all the files one by one.然后使用一个循环将所有文件一一读取。
Link for reference: Python glob multiple filetypes参考链接: Python glob 多种文件类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.