Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 洗牌熊猫列_Python 3.x_Pandas_Shuffle - Fatal编程技术网

Python 3.x 洗牌熊猫列

Python 3.x 洗牌熊猫列,python-3.x,pandas,shuffle,Python 3.x,Pandas,Shuffle,我有以下数据框: Col1 Col2 Col3 Type 0 1 2 3 1 1 4 5 6 1 2 7 8 9 2 我想要一个混合输出,比如: Col3 Col1 Col2 Type 0 3 1 2 1 1 6 4 5 1 2 9 7 8

我有以下数据框:

    Col1  Col2  Col3  Type
0      1     2     3     1
1      4     5     6     1
2      7     8     9     2
我想要一个混合输出,比如:

        Col3  Col1  Col2  Type
    0      3     1     2     1
    1      6     4     5     1
    2      9     7     8     2
如何实现这一点?

与轴=1一起使用:

df = df.sample(frac=1, axis=1)
如果需要最后一列未更改位置:

a = df.columns[:-1].to_numpy()
np.random.shuffle(a)
print (a)
['Col3' 'Col1' 'Col2']

df = df[np.append(a, ['Type'])]
print (df)
   Col2  Col3  Col1  Type
0     3     1     2     1
1     6     4     5     1
2     9     7     8     2

你能帮我再问一个我昨天贴出的问题吗?我明白了,核对一下。这就是我要说的问题: