I have a dataframe where one column in that dataframe has the GPA of first-year students. I want to loop through this column and append to a list of lists all values that fall within 0.4 units of each other. For example, if I have the values (0.4, 0.6, 0.8, 3, 3.4), then I want my list to be [[0.4,0.6,0.8], [3, 3.4]].
This is the code I have tried.
averages = [[] for w in range(len(df['GPA_year1'])//4)]
small = min(df['GPA_year1']) + 0.4
for i in range(len(averages)):
for y in range(len(df['GPA_year1'])):
if small - 0.4 <= df['GPA_year1'][y] <= (small + 0.4):
averages[i].append(df['GPA_year1'][y])
small = small + 0.4
However, when I run this code in Jupyter Notebook, it seems to run forever, which makes me think that there may be an infinite loop somewhere (?) but I'm not sure where the infinite loop might be.
Here is the dataframe
