Luis Bonilla
Luis Bonilla

Reputation: 21

Randomizing DataFrame rows

If a create a DataFrame Object, lets say df = pd.DataFrame({'A':range(5), 'B':range(5)}, and try to randomize some rows with df.reindex(np.random.permutation(df.index)) I get

>>> df = pd.DataFrame({'A':range(5), 'B':range(5)})
>>> df
   A  B
0  0  0
1  1  1
2  2  2
3  3  3
4  4  4
>>> df.reindex(np.random.permutation(df.index))
   A  B
3  0  0
0  1  1
1  2  2
2  3  3
4  4  4

Numpy version is 1.15.0

Pandas version is 0.23.3

Any idea why it is just mixing the indexes and not the whole rows?

Upvotes: 2

Views: 103

Answers (0)

Related Questions