Reputation: 188
I have a python dataframe as follows:
AssignmentID Student Assignment_submitted Passed
1 stud1 1 1
2 stud2 1 1
3 stud3 1 1
4 stud1 2 0
5 stud4 1 1
6 stud1 3 0
What I want to do is convert this into following dataframe:
AssignmentID Student Assignment_submitted Passed TotalSubmitted
1 stud1 1 1 3
2 stud2 1 1 1
3 stud3 1 1 1
4 stud1 2 0 3
5 stud4 1 1 1
6 stud1 3 0 3
Upvotes: 0
Views: 18
Reputation: 323236
Check with transform
df['TotalSubmitted']=df.groupby('Student')['Assignment_submitted'].transform('count')
Upvotes: 2