简体   繁体   中英

Pandas Value_Counts Selection

Below is the output of the -

df['x'].value_counts()

-1    266551
 1    172667
 0    155994

I would like to calculate the maximum of the counts except of the value -1.

In this case, answer would be 172667.

How can i remove the value of -1 from it and select the max of other values?

Use drop + max :

df['x'].value_counts().drop(-1).max()

Sample:

s = pd.Series([266551,172667,155994], index=[-1,1,0])
print (s)
-1    266551
 1    172667
 0    155994
dtype: int64

print (s.drop(-1).max())
172667

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