新数据按 python(pandas?)重复排序

New data ordering with python (pandas?) with repetition

我想使用 PYTHON.

修改以下格式的文件

来自这里:

0.0000 2.0200
0.0000 2.0400
0.0000 2.0800
0.0000 2.1200
0.0100 0.0000
0.0100 1.2400
0.0100 1.2600
0.0100 1.5800
0.0200 1.6600
0.0200 1.7000
0.0200 1.7800
0.0200 1.9800 

对此:

0.0000 2.0200 2.0400 2.0800 2.1200
0.0100 0.0000 1.2400 1.2600 1.5800
0.0200 1.6600 1.7000 1.7800 1.9800 

有人有什么建议吗? 提前致谢。

使用 Numpy reshapeunique:

data = [
 [0.0, 2.02],
 [0.0, 2.04],
 [0.0, 2.08],
 [0.0, 2.12],
 [0.01, 0.0],
 [0.01, 1.24],
 [0.01, 1.26],
 [0.01, 1.58],
 [0.02, 1.66],
 [0.02, 1.7],
 [0.02, 1.78],
 [0.02, 1.98]
]

# convert to numpy array
a = np.array(data)

# get unique indices
n = np.unique(a[:,0])

reshape the values to match the index length
v = np.reshape(a[:,1], (len(n),-1))

# re-combine the index and values
t = np.concatenate([n.reshape(-1,1),v],axis=1)