I would like to shuffle each 5 rows together without changing the order in that group.
Asked
Active
Viewed 129 times
1 Answers
1
Pulling from: https://stackoverflow.com/a/44729807/7253453
You can achieve this by
import random
n = 5 #chunk row size
list_df = [df[i:i+n] for i in range(0,df.shape[0],n)]
random.shuffle(list_df)
df = pd.concat(list_df)

Bobs Burgers
- 761
- 1
- 5
- 26