I have two dataframes, A and B , with dimension MxN which rows I want to random shuffle. A and B have the same column names and indexes. I know how to shuffle data inside each column with df.apply(np.random.shuffle) method, but it permutate differently each column. I want that if the first row of A becames the second row after shuffle, the first row of B becames the second row too, etc. How can I do what I want?
Asked
Active
Viewed 1,297 times
2 Answers
0
This doesn't use pandas but works
from random import shuffle
ind_list=[i for i in range(M)]
shuffle(ind_list)
A=A[ind_list,:]
B=B[ind_list,:]

fireball.1
- 1,413
- 2
- 17
- 42