重塑具有多列但列名相同的数据框

reshape data frame with multiple columns but same column names

你好,我有一个数据框,其中 1 "unique id" 作为索引,但在 unique_id 的一长行中有相同的 3 个不同数据的问题。我研究了堆栈、熔化、旋转 table。尝试用

重塑下面的数据

"Given" enter image description here

最终产品:enter image description here

提供代码的结果:enter image description here

最近的代码输入:enter image description here

df = df.set_index(['Unique_ID'])
samples_per_id = len(df.columns) // 3
chunks = map(lambda k: df.iloc[:, k:k+3], range(0, samples_per_id, 3))
result = pd.concat(chunks, axis=0)

最终,result = result.sort_index()