noob
noob

Reputation: 3811

Counting number of values in each bin : Python

workbook dataframe

Scores     Score Bins   
22         (0, 25] 
54         (50,75]
209        (200, 225]         
0          (0, 25]  

I am unable to find the number of values corresponding to each bin. For example I want to find out how many values are in bin (0, 25], (25, 50] etc.

Output I want

Number of values in bin (0,25]: _____
Number of values in bin (25,50]: _____
and so on

Upvotes: 0

Views: 96

Answers (2)

phi
phi

Reputation: 11704

workbook['Score Bins'].value_counts()

Upvotes: 1

Richard Nemeth
Richard Nemeth

Reputation: 1864

I'd suggest to use the value_counts method:

workbook['Score Bins'].value_counts()

It will return a pandas Series with counts for each unique value of the specific column, f.e.:

(200, 225]    25
(175, 200]    25
(150, 175]    25
(125, 150]    25
(100, 125]    25
(75, 100]     25
(50, 75]      25
(25, 50]      25
(0, 25]       25

Upvotes: 1

Related Questions