Below is some dummy code of what I would like to achieve and my question is at the end.I would like to shuffle blocks of data frame (different sizes) in a list in Python. Thanks.
Set up a dummy dictionary:
dummy = {"ID":[1,2,3,4,5,6,7,8,9,10],
"Alphabet":["A","B","C","D","E","F","G","H","I","J"],
"Fruit":["apple","banana","coconut","date","elephant apple","feijoa","guava","honeydew","ita palm","jack fruit"]}
Turn dictionary into data frame:
dummy_df = pd.DataFrame(dummy)
Create blocks of data frame with required size:
blocksize = [1,2,3,4]
blocks = []
i = 0
for j in range(len(blocksize)):
a = blocksize[j]
blocks.append(dummy_df[i:i+a])
i += a
blocks
Below is the output of "blocks". It is 4 blocks of data frame with size of 1-4 rows in a list:
[ ID Alphabet Fruit
0 1 A apple,
ID Alphabet Fruit
1 2 B banana
2 3 C coconut,
ID Alphabet Fruit
3 4 D date
4 5 E elephant apple
5 6 F feijoa,
ID Alphabet Fruit
6 7 G guava
7 8 H honeydew
8 9 I ita palm
9 10 J jack fruit]
I am stuck after the above.
I have tried many different things but kept getting errors. I would like to shuffle those blocks of data frame in the list, then combined them back into a dataframe. Below is an example of the shuffled output. How could I do this please?
Example ideal output:
ID Alphabet Fruit
1 2 B banana
2 3 C coconut
0 1 A apple
6 7 G guava
7 8 H honeydew
8 9 I ita palm
9 10 J jack fruit
3 4 D date
4 5 E elephant apple
5 6 F feijoa