Project 1: App store analysis: Why does my function work for android, but not iOS?

Here I am creating a dictionary which will identify the latest duplicate app based on the largest review count. My function works great for android, but for iOS, it takes out far too many records:

def create_review_count_dictionary(name_column_num, review_column_num, dataset):
    review_count_dict = {}

    for app in dataset[1:]:
        app_name = app[name_column_num]
        if app_name not in review_count_dict:
            review_count_dict[app_name] = float(app[review_column_num])
        else:
            if float(review_count_dict[app_name]) < float(app[review_column_num]):
                review_count_dict[app_name] = float(app[review_column_num])
    return review_count_dict

Here is the function call:

and_review_count_col_num = 3
ios_review_count_col_num = 5
and_name_col_num = 0
ios_name_col_num = 1

print('Length of dict for Android: ', 
      len(create_review_count_dictionary(and_name_col_num , and_review_count_col_num, android)))
print('Length of dict for iOS: ', 
      len(create_review_count_dictionary(ios_name_col_num , ios_review_count_col_num, ios)))

Expected output of length of dictionary for ios is 7196 but it gives a length of 3199!

I copied the code here but I wasn’t able to replicate your results. I ended up with a dictionary size of 7195. My first thought is to inspect the ios variable and make sure it has the number of rows it’s supposed to. If you have more info or get it figured out, let us know!

1 Like

OK. I am sure the ios variable is where the trouble lies. Could mean my whole project is affected. Thank you for pointing this out and trying out my code!

Wow. This is very strange but now it shows the correct length of the dict. I have no idea how it ended up fixed but it’s working! Can’t look a gift-horse in the mouth. Thank you!

1 Like

I think the issue was with the order of running my cells. I must have run them out of order!

Ah, that makes sense! Glad you caught it!

1 Like