此问题已在此处有答案:
Pandas Groupby Select Groups that Have More Than One Unique Values in a Column(5个答案)
Pandas - Keeping groups having at least two different codes(2个答案)
14天前关闭
APandas解决方案当值B不相同对于相同A值时获取结果数据框
输入:
colA colB
a 1 <--
b 2
a 1 <--
a 0 <-- different
字符串
输出:
colA colB
a 1 <--
a 1 <--
a 0 <-- different
型
解决方案:
Pandas Groupby Select Groups that Have More Than One Unique Values in a Column的
out = df.groupby(['a']).filter(lambda x: x['b'].nunique() > 1)
型
@mozway评论也有效
out = df[df.groupby('colA')['colB'].transform('nunique').gt(1)]
型
1条答案
按热度按时间jfgube3f1#
字符串
如果你不想重复:
型