在Python DataFrame中,对于一个MemberID,我有多行,其中某些列的某些空值如下所示:
Date MemberID Name Education Occupation Gender
0 2017/01 001 A Nan Student M
1 2017/02 001 A Graduate Nan M
2 2017/03 001 A Nan Physician M
3 2017/01 002 B College Nan F
4 2017/02 002 B Nan Professor Nan
5 2017/03 002 B PHD Nan F
我想使用以下输出清除数据:
使用相同MemberID的最新信息填充NULL值。
Date MemberID Name Education Occupation Gender
0 2017/03 001 A Graduate Physician M
1 2017/03 002 B PHD Professor F
谢谢。
答案 0 :(得分:1)
您可以使用.groupby
和.last
:
df.groupby('MemberID').last()
输出:
Date Name Education Occupation Gender
MemberID
1 2017/03 A Graduate Physician M
2 2017/03 B PHD Professor F