我想重新排列我的Excel文件:
成为:
认为可以用pandas groupby()完成
:infile = pd.DataFrame(pd.read_excel("test.xlsx", header = 0))
# Extract the header and create new data frame
sample_list = infile["Sample"].drop_duplicates().tolist()
output = pd.DataFrame(columns=sample_list)
# Adding data group wise. This doesn't really do the trick though...
groups = infile.groupby("Sample")
for sample in range(len(sample_list)):
output = output.append(groups.get_group(sample_list[sample])["Type"], ignore_index=True)