mercredi 26 février 2020

How do I randomize without repetion in python dataframe?

With a data frame, how do I randomize it so that it is truly mixed up? Such that the rows that were beside each other in the original table are not together anymore.

For example with this table.

U         A         B         C
0  1.438161 -0.210454         0
1 -0.283780 -0.371773         0
2  0.552564 -0.610548         0
3  1.931332  0.649179         1
4  1.656010 -1.373263         1
5  0.142682 -0.657849         1
6  1.754264 -0.610548         0
7  1.341232  0.649179         0
8  1.656010 -1.373263         0
9  0.944862 -0.657849         0

How do I make so that it looks something like this? (By randomizing)

U         A         B         C
1 -0.283780 -0.371773         0
3  1.931332  0.649179         1
0  1.438161 -0.210454         0
4  1.656010 -1.373263         1
8  1.656010 -1.373263         0
6  1.754264 -0.610548         0
2  0.552564 -0.610548         0
7  1.341232  0.649179         0
9  0.944862 -0.657849         0
5  0.142682 -0.657849         1

Notice that the index numbers in the second table do not have any values that either goes up or goes down in consecutive order (ie, no 6, 7 or 4,3)




Aucun commentaire:

Enregistrer un commentaire