Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- data = [['Alex',10],['Bob',12],['Clarke',13],['Alex',12],['Bob',18],['Clarke',11],['Alex',10],['Bob',12],['Clarke',13],['Alex',10],['Bob',14],['Clarke',16]]
- df = pd.DataFrame(data,columns=['Name','Score'])
- # create groupby variable that groups Scores by Name
- groupby_score = df["Score"].groupby(df["Name"]) #view grouping with list(groupby_score)
- # loop over each group and and print
- for groups, age in groupby_score:
- print(groups, age)
- # loop to check if difference of all scores in group are within a range of 5
- # Ex: Alex's scores are 10, 12, 10, 10. Because the max difference between any two scores is 2, this group is within range
Advertisement
Add Comment
Please, Sign In to add comment