我有下面的DF,我想要处理成像下面的样本。我有一个困难的时间,因为识别符是分享他们所在的网站的列。柱子的位置也不是固定的,因为在某些情况下,“地”有30天,而“水”只有5天
谢谢你对我的照顾
示例df:
df = pd.DataFrame({'Unnamed: 0': ['Site',"A", "B","C"],
'Unnamed: 1': ['Identifier 1',"Land", "Land","Land"],
'Unnamed: 2': ['Day 1',1, 2,3],
'Unnamed: 3': ['Day 2',4, 5,6],
'Unnamed: 4': ['Day 3',7, 8,9],
'Unnamed: 5': ['Day 4',10, 11,12],
'Unnamed: 6': ['Identifier 2',"Water", "Water","Water"],
'Unnamed: 7': ['Day 1',13, 14,15],
'Unnamed: 8': ['Day 2',16, 17,18],
'Unnamed: 9': ['Day 3',19, 20,21],
'Unnamed: 10': ['Day 4',22, 23,24],
})
输出文件:
Site Identifier 1 Day 1 Day 2 Day 3 Day 4
A Land 1 4 7 10
B Land 2 5 8 11
C Land 3 6 9 12
A Water 13 16 19 22
B Water 14 17 20 23
C Water 15 18 21 24
1条答案
按热度按时间dtcbnfnu1#
这是你想要的吗?我首先将 Dataframe 拆分成两个 Dataframe ,每个 Dataframe 包含不同的标识符,最后将它们合并回tgt。以下是代码,希望它能有所帮助。
编辑-用于动态N列