重新排序数据框的列索引

Reordering column index of a dataframe

我有一个 15k 列的数据框。这些列将被重新排序。这样的。这些列排列如下:

1) 第一列的值应为第三 2) 第二列的值应为第一列 3) 第三列的值应为 first

现有列

0 1 2 3 4 5 6 7 8 .....14998 14999 15000

所需的列

2 0 1 5 3 4 8 6 7 .... 15000 14998 14999

IIUC,更简单的解决方案:

import itertools

k = [2, -1, -1] * (len(x)//3)
indexes = np.arange(15000) + np.array(k)

df.iloc[:, indexes]

你只需要正则表达式!

teststring=" ".join(str(i) for i in range(0,15000))
replacedstring=re.sub(r'((\d+) (\d+) (\d+))',r'  ',teststring)
replacedstring.split(" ")