Issue
I am quite new to Python dataframes.
In the following case:
id | name | result |
---|---|---|
1 | Cara | A |
2 | Ben | B |
3 | Evie | A |
4 | Mel | C |
I want to return the name of the student who has the first occurrence of result A (Cara). I want to then go and do the same for the second occurrence of A (Evie) and repeat until 5 occurrences. How would I do this?
Solution
Try this:
students=df.loc[df[result]=="A"].head(5)
print(student["name"].to_list())
Answered By - Hanna
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.