首页 > 解决方案 > 如果两列相等,如何删除重复项

问题描述

数据框是

View              player  country
Admin_Case_View  ckear    USA
Admin_Case_View  ckear  
Admin_Case_View  ckear  
Admin_Questions  jungeunk  KOR
Admin_Questions  jungeunk   

如果view == player,则删除重复项,并且国家列中的位置为空。

所需的输出应该是

View              player  country
Admin_Case_View  ckear    USA   
Admin_Questions  jungeunk  KOR

标签: python-3.xpandasnumpy

解决方案


就像是

df.dropna(subset=['country']).drop_duplicates(subset=['View', 'player'])

如果我理解正确,应该可以解决问题。


推荐阅读