In [2]:
import pandas as pd
import numpy as np
In [16]:
df = pd.DataFrame({'i':range(20),
                   'L':[chr(97+i) for i in range(20)]
                  })

df['L2'] = df['L']
In [17]:
df.T
Out[17]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
L a b c d e f g h i j k l m n o p q r s t
L2 a b c d e f g h i j k l m n o p q r s t
In [20]:
n_rows=len(df)
n_shuffle=int(n_rows*0.4)
n_rows, n_shuffle
Out[20]:
(20, 8)
In [12]:
pick_rows=np.random.permutation(list(range(n_rows)))[0:n_shuffle]
pick_rows
Out[12]:
array([ 3,  0, 11, 16, 14,  4,  8, 12])
In [13]:
shuffled_values=np.random.permutation(df['L2'][pick_rows])
shuffled_values
Out[13]:
array(['l', 'e', 'd', 'q', 'o', 'i', 'm', 'a'], dtype=object)
In [14]:
df['L2'][pick_rows]=shuffled_values
C:\Users\adumont\.conda\envs\fastai-cpu\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """Entry point for launching an IPython kernel.
In [15]:
df.T
Out[15]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
L a b c d e f g h i j k l m n o p q r s t
L2 e b c l i f g h m j k d a n o p q r s t