I would like to come up with the 4th column below based on the first three:
user job time Rank
A print 1559 2
A print 1540 2
A edit 1520
First, assign a new column which contains the minimum time for user-job pairs:
df['min_time'] = df.groupby(['user', 'job'])['time'].transform('min')
Then group by each user and rank them:
df.groupby('user')['min_time'].rank(method='dense').astype(int)
Out:
0 2
1 2
2 1
3 1
4 3
5 2
6 2
7 2
8 1
9 1
Name: min_time, dtype: int64