我遍历了一个excel文件文件夹,将它们转换为dataframes,并将这些数据文件放入字典中,其中键是文件名。我想要做的是在文件名不重要的地方制作这个大数据,因为我需要的数据的列名是唯一的。我想合并‘基因’列,因为他们重复,填充NaN分数w/零,并删除‘比率’栏。
import numpy as np
import pandas as pd
import math
import os
folder = r'C:\Users\camer\Desktop\Stack Overflow' # Folder path
files = os.listdir(folder)
dict1 = {}
for file in files:
if file.endswith('.xlsx'):
df1 = pd.read_excel(os.path.join(folder,file))
dict1[file] = df1
# Putting all excel files from file into dataframes, then setting those dataframes as the values in the preallocated dict,
# where the keys are the file names
df1 = pd.concat(dict1, axis=1)
df1

如果我试图在dataframe仍然用文件名分隔时对基因列进行分组,我会得到以下结果:
df1 = pd.concat(dict1, axis=1)
df1 = df1.groupby(df1.columns, axis=1).sum()
df1

发布于 2021-04-26 18:18:44
我认为这应该适用于你:
pd.concat(dict1.values())https://stackoverflow.com/questions/67271760
复制相似问题