I have a data frame of students sorted by grade that I want to split into 3 data frames, such that an even number of students per grade is in each of the 3 groups. I thought of it like dealing cards, you know passing one card to each of 3 people in turns, but would like to know of a more efficient way:
for i in range(0, len(blue), 3):
blue_1_df.loc[len(blue_1_df)] = blue.iloc[i]
if i+1 < len(blue):
blue_2_df.loc[len(blue_2_df)] = blue.iloc[i+1]
if i+2 < len(blue):
blue_3_df.loc[len(blue_3_df)] = blue.iloc[i+2]
The conditions in the loop prevent index out of range errors in case the data frame being divided up is not divisible by 3. This works but I would like to know what would be more efficient.