I have the following dataframe:
df = pd.DataFrame({"marks": [40, 60, 90, 20, 100, 10, 30, 70 ], "students":
["Jack", "Jack", "Jack", "Jack", "John", "John", "John", "John"]}
)
marks students
0 40 Jack
1 60 Jack
2 90 Jack
3 20 Jack
4 100 John
5 10 John
6 30 John
7 70 John
I am attempting to assign a student's average to his marks below 40 (the average will include the lowest mark).
I am aware of assigning a mark based on the < 40 condition (in this case I assigned the lowest mark of the df to all marks below 40), like so:
df.loc[df["marks"] < 40, "marks"] = df["marks"].min()
But I am confused on how to potentially apply a lambda function on unique student names. Any help would be appreciated.