Tinzyl
Tinzyl

Reputation: 35

Counting values in a range

I am trying to get the number of employees with a salary in a certain range. How can I output the number just for the 'Salary' column.

salaryEmp = data4[data4.Salary.between(100, 500)].count()

Upvotes: 2

Views: 1255

Answers (3)

Guilherme Marques
Guilherme Marques

Reputation: 263

I would do something like:

len(data4[(data4.Salary>100) & (data4.Salary<500)])

Upvotes: 0

rafaelc
rafaelc

Reputation: 59274

Use

df.loc[df.Salary.between(100,500), 'Salary'].count()

Upvotes: 3

BENY
BENY

Reputation: 323266

You can try value_counts

data4.Salary.value_counts(bins=[100,500])

Upvotes: 3

Related Questions