更新时间:2023-01-21 19:01:20
使用简单的 loc
df.loc[df.C.duplicated(), ['A', 'B']] = ''
A B C D
0 1 5 a c
1 a d
2 3 6 b e
3 4 7 c f
还可以使用 np.nan
代替空字符串,以免与dtypes混淆
Can also use np.nan
instead of empty string not to mess with the dtypes