[英]Reordering column index of a dataframe
I have a data frame of 15k columns. 我有一个15k列的数据框。 These columns are to be re-ordered.
这些列将重新排序。 Such that.
这样的。 These columns are arranged as follows:
这些列的排列方式如下:
1) The first column should have values of third 2) The second column should have values of first 3) The third column should have values of first 1)第一列的值应为第三个值2)第二列的值应为第一个值3)第三列的值应为第一个值
Existing Column 现有栏
0 1 2 3 4 5 6 7 8 .....14998 14999 15000 0 1 2 3 4 5 6 7 8 ..... 14998 14999 15000
Desired Columns 所需列
2 0 1 5 3 4 8 6 7 .... 15000 14998 14999 2 0 1 5 3 4 8 6 7 .... 15000 14998 14999
IIUC, even simpler solution: IIUC,甚至更简单的解决方案:
import itertools
k = [2, -1, -1] * (len(x)//3)
indexes = np.arange(15000) + np.array(k)
df.iloc[:, indexes]
All you need is regex! 您只需要正则表达式!
teststring=" ".join(str(i) for i in range(0,15000))
replacedstring=re.sub(r'((\d+) (\d+) (\d+))',r'\4 \2 \3',teststring)
replacedstring.split(" ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.