简体   繁体   中英

pandas - count frequency of unique value in a column

How can i exclude 0.0 column showing count value of 942, display only non zero column.

input:

 df.groupby('WASHING CONTAINER AGENT').size()

output:

WASH - CHEMICAL
0.0     942
12.0     20
20.0      8
dtype: int64

Would this be acceptable:

df[df['WASHING CONTAINER AGENT']>0].groupby('WASHING CONTAINER AGENT').size()

And for your other question, hopefully this would do the trick:

df[df.iloc[:, 9:33].ne(0)].apply(lambda x: x.value_counts()).T.stack()

假设在“ groupby”的第一个输出中有0.0、12.0、20.0作为键:请尝试此操作。

df = df.groupby('WASHING CONTAINER AGENT').size()[lambda x: x.index > 0.0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM