Hello everyone. I am working on the first guided project and I’m getting a unexpected result. Basically, I’m running a loop to clear some data using
.remove(row). When I run the loop the first time I get one result that I expect to be final, but it changes if I run the loop more than once. After a few times (this is consistent) it doesn’t change any more. Thanks for your help.
import csv from csv import reader opened_file = open('googleplaystore.csv') read_file = reader(opened_file) android_data = list(read_file) android_data = android_data[1:] print(len(android_data))
special_character_android =  for row in android_data: c_count = 0 app_name = row for character in app_name: if ord(character) > 127: c_count += 1 if c_count > 2: special_character_android.append(row) android_data.remove(row) print(len(android_data)) print(len(special_character_android)) if len(special_character_android) < 10: print(special_character_android)
The output from the first block is
10841. This stays consistent.
If you run the second block one time you get
If you run it a second time you get
[['あなカレ【BL】無料ゲーム', 'FAMILY', '4.7', '6073', '8.5M', '100,000+', 'Free', '0', 'Mature 17+', 'Simulation', 'February 25, 2018', '4.2.2', '2.3 and up']]
Why am I not catching this row the first time? I’m having a similar problem in the attached notebook (it takes multiple loops to stop changing), except there I’m also running a loop to catch
for row in android_data: if row != 'Free': android_data.remove(row)
and it runs multiple times before the data set stops changing. There may be entirely different reasons but it seems like the same behavior.
App Downloads Project.ipynb (25.1 KB)
googleplaystore.csv (1.3 MB)