CYBER WEEK - EXTRA SAVINGS EVENT
TRY A FREE LESSON

Guided Project 1: Profitable Apps - What would be the best approach to "Scan" list of lists to check for blank spaces?

Screen Link:

https://app.dataquest.io/c/112/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/3/deleting-wrong-data

My Code:

#Open and read dataset and copy dataset as list of lists

opened_file = open('googleplaystore.csv', encoding="utf8")
read_file = reader(opened_file)
android = list(read_file)
android_header = android[0]
android = android[1:]

#Try to find rows with empty cells 

len_android_header = len(android_header)

for row in android:
    if len(row) != len_android_header:
        print(row)

What I expected to happen:
The expected result was output to show the row with unequal length (compared to header). The android list (of lists) with index 10472 has empty spaces as pointed out in the discussion forum and in the solution as well. So, I wanted to use a for loop to check for lists of shorter length.

What actually happened:
Output shows nothing. The above code did not help because the list index 10472 shows empty elements as ’ ’ and it counts those empty spaces as elements within the list. Therefore, length of the list with index 10472 is same as length of android_header.

1 Like

Hi @sky2397,

This will work:

for row in android:
    if '' in row:
        print(row)
1 Like

Or even better, run this code:

for i in range(len(android)):
    row = android[i]
    if '' in row:
        print(row,  i)

Then you’ll see both the row itself and its index.

2 Likes

Elena, many thanks for your response! :smiley:

1 Like