I have a pandas data frame with large number of columns:
Col1 Col2 Col3 Col4
A1 B3 C2 D4
A2 B4 C3 D2
A5 B2 C1 D1
A4 B3 C2 D4
A5 B4 C3 D2
A2 B3 C4 D1
A3 B2 C3 D4
A1 B4 C3 D2
A4 B2 C1 D1
I want to split this data frame into n chunks so that each chunk has at least one row that belongs to all the unique values of col4.
For example: if n=3
df1:
Col1 Col2 Col3 Col4
A1 B3 C2 D4
A2 B4 C3 D2
A5 B2 C1 D1
df2:
Col1 Col2 Col3 Col4
A4 B3 C2 D4
A5 B4 C3 D2
A2 B3 C4 D1
df3:
Col1 Col2 Col3 Col4
A3 B2 C3 D4
A1 B4 C3 D2
A4 B2 C1 D1