Reputation: 29
df = pd.DataFrame({'Score':[1,2,3,4,5], 'Rate': [1.0, 0.0, 0.0, 0.5, 0.5]})
df.head()
Score Rate
0 1 1.0
1 2 0.0
2 3 0.0
3 4 0.5
4 5 0.5
I am trying to count the number of Rates equal to 0 and show the corresponding score
Upvotes: 0
Views: 903
Reputation: 862641
Use DataFrame.loc
with boolean indexing
and then get counts and sum of colun Score
:
df = df.loc[df['Rate'].eq(0), 'Score'].agg(['sum','size'])
print (df)
sum 5
size 2
Name: Score, dtype: int64
Upvotes: 0
Reputation: 19947
you can use loc:
df.loc[df.Rate.eq(0)]
Score Rate
1 2 0.0
2 3 0.0
Or if you just need to see Score:
df.loc[df.Rate.eq(0)].Score
Upvotes: 1