Keep IF function running in a loop and putting IFs together

Hi all,

I am going deeper into the App Store and Google Play project and I am trying to get a sample of apps that:

  • Have a rating bigger than 4: first IF
  • Are in the ‘Photo & Video’ or ‘Games’ categories: second if
  • Have more than 100000 ratings

However, when I execute the code I found out that when it gets to the last IF it stops the loop as soon as it cannot find an app with more than 100000 ratings. I want the code to continue iterating over everything and show me all the apps with more than 100000 ratings.

When I tried to put all the IFs together with AND functions, I also found out that not all the IF conditions would work, often finding ratings lower than 4.

What am I missing?

My Code:

sample_for_devs_Apple = []
well_rated_sample_Apple = []
for apps in final_dataset_Apple[1:]:
    ratingApple = float(apps[7])
    if ratingApple > 4.0:
for appsApple in well_rated_sample_Apple:
    user_rating_count_Apple = float(appsApple[5])
    genre_Apple = appsApple[11]
    if genre_Apple == ('Photo & Video' or 'Games'): 
final_sample_with_installs_for_devs_Apple = []
for apps in sample_for_devs_Apple:
    names_Apple_sample = apps[1]
    ratings_Apple_sample = apps[7]
    rating_count_Apple_sample = float(apps[5])
    if rating_count_Apple_sample > 100000:

1 Like

Hi @carlosaguirrebeitia, the mistake you made is from this part of the code.

Your plan is to get samples of apps that are in either

To do that you separate them

if genre_Apple == (‘Photo & Video’) or (‘Games’):

The or keyword is used to determine if at least one of the operands is truth. An or statement returns the first operand if it is truthy and otherwise returns the second operand

I hope this helps, else let me know if i misconstrued your question,


Hi @OlutokiJohn thank you!

It almost worked. I got now a much bigger sample. It also gave me a bigger sample when I removed the parenthesis altogether.

However, I had to replace the line with:

if genre_Apple == 'Games' or genre_Apple == 'Photo & Video': 

With the line you recommended some other categories such as ‘Shopping’ and ‘Lifestyle’ slipped into the sample. Do you or anyone know why?

The second million-dollar-question is, do you know what was my code returning when I wrote the code below?

if genre_Apple == ('Photo & Video' or 'Games')

Thank you!