path = '/Desktop/somefolder'
for filename in os.listdir(path):
with open(path+filename) as f:
- read the 3-4 excel files and attach the path
- be able to concat them based on a specific column
文件名给出了我在目录中的文件名。我的想法是将文件名与路径连接起来,以便能够读取和连接它们。
我不知道如何使用文件名,以便能够将其加载为df并将其连接起来。
发布于 2022-11-10 19:55:15
尝试:
import pandas as pd
import os
path = '/Desktop/somefolder/'
dfs = []
for filename in os.listdir(path):
dfs.append(pd.read_excel(path+filename, engine='openpyxl'))
pd.concat(dfs, axis=0)
发布于 2022-11-10 19:52:09
将数据读入数据帧
df1 = pd.read_excel('file1.xlsx')
df2 = pd.read_excel('file2.xlsx')
创建过滤后的数据帧
df1Filtered = df1[df1["YourColumnName"].("YourColumnValues")
df2Filtered = df2[df2["YourColumnName"].("YourColumnValues")
连接过滤后的数据帧
NewDF = pd.concat([df1Filtered, df2Filtered])
编写一个新文件到excel
NewDF.to_excel('NewFile.xlsx')
https://stackoverflow.com/questions/74394405
复制相似问题