如何随机打乱DataFrame

来源:互联网 发布:淘宝香港代购好的店铺 编辑:程序博客网 时间:2024/05/22 04:49
 from pandas import DataFrame import numpy as npdf=DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four'])  dfOut[8]:    one  two  three  foura    0    1      2     3b    4    5      6     7c    8    9     10    11d   12   13     14    15from sklearn.utils import shuffledf = shuffle(df)dfOut[11]:    one  two  three  fourb    4    5      6     7a    0    1      2     3d   12   13     14    15c    8    9     10    11
原创粉丝点击