0

I would like to shuffle each 5 rows together without changing the order in that group.

Alex Davies
  • 191
  • 2
  • 11

1 Answers1

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