2024-04-25 23:22:10 发布
网友
df.groupby(['name','cat'])['valtocount'].agg('count')
通过以上步骤,我得到了以下多指标df:
name cat count abc a 1 b 1 def a 1 c 2
我只想保留计数标准为>;0 你们有什么建议吗
将^{}与std或^{}一起使用,并通过^{}进行过滤:
std
s = df.groupby(['name','cat'])['valtocount'].agg('count') s1 = s[s.groupby(level=0).transform('std') > 0] print (s1) name cat def a 1 c 2 Name: valtocount, dtype: int64
s1 = s[s.groupby(level=0).transform('nunique') != 1]
将^{} 与} 一起使用,并通过^{} 进行过滤:
std
或^{相关问题 更多 >
编程相关推荐