1 回答
TA贡献1824条经验 获得超8个赞
尝试这个:
df['var'] = (df.male + df.female).groupby(df.emp_id).transform('min')
In [39]: df
Out[39]:
emp_id male female Month_Year var
0 423 0 0 March-2016 0
1 423 0 0 April-2016 0
2 423 0 1 May-2016 0
3 423 0 1 June-2016 0
4 789 1 0 June-2017 0
5 789 1 0 July-2017 0
6 789 1 0 August-2017 0
7 789 0 0 September-2017 0
8 856 1 0 March-2018 1
9 856 1 0 April-2018 1
10 987 0 1 June-2019 1
11 987 0 1 July-2019 1
12 987 0 1 August-2019 1
添加回答
举报