shuffle data python code example
Example 1: python randomize list
import random
random.shuffle(list)
Example 2: shuffle dataframe python
df = df.sample(frac=1).reset_index(drop=True)
Example 3: randomly shuffle array python
import random
l = list(range(5))
print(l)
# [0, 1, 2, 3, 4]
lr = random.sample(l, len(l))
print(lr)
# [3, 2, 4, 1, 0]
print(l)
# [0, 1, 2, 3, 4]