BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Explore_data() throws an error in Project 1:Profitable App Profiles for the App Store and Google Play Markets

Screen Link:

https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/5/removing-duplicate-entries-part-two

My Code:

def explore_data(dataset, start, end, rows_and_columns = False):
    dataset_slice = dataset[start:end]
    for row in dataset_slice:
        print(row)
        print()
        
    if rows_and_columns:
        print('Number of rows:', len(dataset))
        print('Number of columns:', len(dataset[0]))
            

print(android_header)
print()
explore_data(android,0,3,True)
android_clean = []
already_added = []

for app in android:
    name = app[0]
    n_reviews = float(app[3])
    
    if (n_reviews == reviews_max) and name not in already_added:
        android_clean.append(app)
        already_added.append(name)
explore_data(android_clean, 0, 3, True)

What I expected to happen:

[‘Photo Editor & Candy Camera & Grid & ScrapBook’, ‘ART_AND_DESIGN’, ‘4.1’, ‘159’, ‘19M’, ‘10,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design’, ‘January 7, 2018’, ‘1.0.0’, ‘4.0.3 and up’]

[‘U Launcher Lite – FREE Live Cool Themes, Hide Apps’, ‘ART_AND_DESIGN’, ‘4.7’, ‘87510’, ‘8.7M’, ‘5,000,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design’, ‘August 1, 2018’, ‘1.2.4’, ‘4.0.3 and up’]

[‘Sketch - Draw & Paint’, ‘ART_AND_DESIGN’, ‘4.5’, ‘215644’, ‘25M’, ‘50,000,000+’, ‘Free’, ‘0’, ‘Teen’, ‘Art & Design’, ‘June 8, 2018’, ‘Varies with device’, ‘4.2 and up’]

Number of rows: 9659
Number of columns: 13

What actually happened:

Number of rows: 0
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-32-2ab54c21bc74> in <module>
----> 1 explore_data(android_clean, 0, 3, True)

<ipython-input-22-3077f5961751> in explore_data(dataset, start, end, rows_and_columns)
      7     if rows_and_columns:
      8         print('Number of rows:', len(dataset))
----> 9         print('Number of columns:', len(dataset[0]))
     10 
     11 

IndexError: list index out of range

Hi. I am stuck on my first project. Though my code is exactly the same as the solution code, but still I end up getting an error as given above. The explore_data() works well when running separately. But when trying by passing the android_clean as an argument, throws an error. Please help!!

This is some great information and tells us where we need to start! The problem (it appears) is with android_clean and no so much a problem with your function explore_data(). You’re getting the error because android_clean is empty.

Looking at your code for how android_clean is created, it looks like your conditional is never being met (i.e. if (n_reviews == reviews_max) and name not in already_added:) and therefore nothing is being appended to it.

Try troubleshooting that section of code a bit more and see if you can’t figure out why android_clean is empty.

  • how is reviews_max defined? Is there a reason why n_reviews == reviews_max never evaluates to True?
  • after running the for loop, is already_added also empty? This is a clear sign that something is wrong with your if statement and should be scrutinized.

I hope this helps and you’re able to figure it out. If not, please let me know what else you learn and we can try something else.

Thank you so much @mathmike314 . I have got the code running without any error.

Nicely done, congrats! Would you mind sharing what was wrong and how you fixed it so that others with a similar problem can learn from you?

i saw an issue with my clipboard which pasted an auto added line of empty dictionary. issue is resolved