[英]How to call all the excel file in a folder and run through the pythons one by one and have the results save in one excel file?
So basically I have multiple excel files (different names) in a folder and I want to copy the same cell (for example B3) from all files and create a column in New excel file and put all the value there.所以基本上我在一个文件夹中有多个 excel 文件(不同的名称),我想从所有文件中复制相同的单元格(例如 B3)并在 New excel 文件中创建一个列并将所有值放在那里。
The file above is what I want to import (multiple files like that).上面的文件是我要导入的(多个文件)。 I want to copy the names and emails and save it to the new file like the one below.我想复制姓名和电子邮件并将其保存到新文件中,如下所示。
So you want to read multiple files, get a specific cell and then create a new data frame and save it as a new Excel file:所以你想读取多个文件,获取一个特定的单元格,然后创建一个新的数据框并将其保存为一个新的 Excel 文件:
cells = []
for f in glob.glob("*.xlsx"):
data = pd.read_excel(f, 'Sheet1')
cells.append(data.iloc[3,5])
pd.Series(cells).to_excel('file.xlsx')
In my particular example I took cell F4 (row=3, col=5) - you can obviously take any other cell that you like or even more than one cell and then save it to a different list, combining the two lists in the end.在我的特定示例中,我采用了单元格 F4 (row=3, col=5) - 您显然可以选择您喜欢的任何其他单元格,甚至多个单元格,然后将其保存到不同的列表中,最后将两个列表组合起来. You could also have more complex logic where you could check one cell to decide which other cell to look at next.您还可以有更复杂的逻辑,您可以在其中检查一个单元格以决定接下来要查看哪个其他单元格。
The key point is that you want to iterate through a bunch of files and for each of them:关键是您要遍历一堆文件并针对每个文件:
Once you've gone through all the files combine all the data in any way that you like and then save it to disk in a format of your choice.浏览完所有文件后,以您喜欢的任何方式组合所有数据,然后以您选择的格式将其保存到磁盘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.