13. Filtering for the Intervals

Hi all,

I am on exercise 13.3 filtering for the intervals on the ’ Python for Data Science: Fundamentals’ on the Dictionary and Frequency Tables section

I’m having a hard time wrapping my head around the logical operators for grouping the frequencies…

The example in the exercise to count the frequency of the group 10,000 - 10,0000 is;

elif 10000 < user_ratings <= 100000:
    user_ratings_freq['10000 - 100000'] += 1

I’m struggling to wrap my head around the logic here, if I wanted to count all the values between 10,000 and 10,0000 would it not be something like elif 10000 >= user_ratings <= 100000?

The way i interpret the example is as if its looking for values less than 10,000 and less than or equal to 10,0000.

I know im interpreting it wrong but i dont see how that makes sense to get the values at or between 10,000 and 10,0000

You need to consider them individually to understand this better.

The first part -

10000 < user_ratings

That’s a straightforward comparison - 10000 less than user_ratings. Or, we can say, user_ratings greater than 10000.

Second part -

user_ratings <= 100000

user_ratings less than or equal to 100000.

So, both together mean - user_ratings greater than 10000 and less than or equal to 100000.

For example, 50000 is greater than 10000 and less than 100000, so it satisfies that condition.

What you suggest -

That’s incorrect. You need values in between that range. So, it can’t be less than 10000 as you suggest. It needs to be greater than 10000 to be in that range.

1 Like