Python Changing Integer To String

Screen Link:
https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/7/removing-non-english-apps-part-two

My Code:

reviews_max = {}

for app in app_data_G [1:] :
    name = app [0]
    n_reviews = float(app[3])
    if name in reviews_max and reviews_max[name] < n_reviews :
        reviews_max[name] += 1
    if name not in reviews_max :
        reviews_max[name] = 1
        
print('Length of reviews max dictonary:', len(reviews_max))

What I expected to happen:
A loop that distinguishes between what is the right number of reviews for a name. It removes duplicates. float(app[3]) should be a numerical value because original data set is a numerical value

What actually happened:
float(app[3]) is now saying 3M which is a string so the code will not run

ValueErrorTraceback (most recent call last)
<ipython-input-15-8c4eddf7dc89> in <module>()
      3 for app in app_data_G [1:] :
      4     name = app [0]
----> 5     n_reviews = float(app[3])
      6     if name in reviews_max and reviews_max[name] < n_reviews :
      7         reviews_max[name] += 1

ValueError: could not convert string to float: '3.0M'

it worked 2 days ago but now its saying this error. My code matches the solution book

Hello @hillary.yeboah,

Try to run all the code cells from the begining. Click on Run All under the cell menu.

unfortunately that did not work . should i post my entire code here

Then you probably haven’t deleted the row with the wrong data. Check this post which already addressed the issue.

that is not the issue. i have copy and pasted my code. please advise

The Number Of Users Who Use Your App
Project Description: Anaylsis on the number of users who use your app

Project Goal: what type of apps are likely to attract more users on Google Play and the App Store.

opened_file = open(‘AppleStore.csv’)
opened_file2 = open(‘googleplaystore.csv’)
from csv import reader
read_file = reader(opened_file)
read_file2 = reader(opened_file2)
app_data_A = list(read_file)
app_data_G = list(read_file2)

def explore_data(dataset, start, end, rows_and_columns=False):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print(row)
print(’\n’) # adds a new (empty) line after each row

if rows_and_columns:
print(‘Number of rows:’, len(dataset))
print(‘Number of columns:’, len(dataset[0]))

explore_data(app_data_A, 0, 3, False)
[‘id’, ‘track_name’, ‘size_bytes’, ‘currency’, ‘price’, ‘rating_count_tot’, ‘rating_count_ver’, ‘user_rating’, ‘user_rating_ver’, ‘ver’, ‘cont_rating’, ‘prime_genre’, ‘sup_devices.num’, ‘ipadSc_urls.num’, ‘lang.num’, ‘vpp_lic’]

[‘284882215’, ‘Facebook’, ‘389879808’, ‘USD’, ‘0.0’, ‘2974676’, ‘212’, ‘3.5’, ‘3.5’, ‘95.0’, ‘4+’, ‘Social Networking’, ‘37’, ‘1’, ‘29’, ‘1’]

[‘389801252’, ‘Instagram’, ‘113954816’, ‘USD’, ‘0.0’, ‘2161558’, ‘1289’, ‘4.5’, ‘4.0’, ‘10.23’, ‘12+’, ‘Photo & Video’, ‘37’, ‘0’, ‘29’, ‘1’]

explore_data(app_data_A, 0, 3, True)
[‘id’, ‘track_name’, ‘size_bytes’, ‘currency’, ‘price’, ‘rating_count_tot’, ‘rating_count_ver’, ‘user_rating’, ‘user_rating_ver’, ‘ver’, ‘cont_rating’, ‘prime_genre’, ‘sup_devices.num’, ‘ipadSc_urls.num’, ‘lang.num’, ‘vpp_lic’]

[‘284882215’, ‘Facebook’, ‘389879808’, ‘USD’, ‘0.0’, ‘2974676’, ‘212’, ‘3.5’, ‘3.5’, ‘95.0’, ‘4+’, ‘Social Networking’, ‘37’, ‘1’, ‘29’, ‘1’]

[‘389801252’, ‘Instagram’, ‘113954816’, ‘USD’, ‘0.0’, ‘2161558’, ‘1289’, ‘4.5’, ‘4.0’, ‘10.23’, ‘12+’, ‘Photo & Video’, ‘37’, ‘0’, ‘29’, ‘1’]

Number of rows: 7198
Number of columns: 16
explore_data(app_data_G, 0, 3, True)
[‘App’, ‘Category’, ‘Rating’, ‘Reviews’, ‘Size’, ‘Installs’, ‘Type’, ‘Price’, ‘Content Rating’, ‘Genres’, ‘Last Updated’, ‘Current Ver’, ‘Android Ver’]

[‘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’]

[‘Coloring book moana’, ‘ART_AND_DESIGN’, ‘3.9’, ‘967’, ‘14M’, ‘500,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Art & Design;Pretend Play’, ‘January 15, 2018’, ‘2.0.0’, ‘4.0.3 and up’]

Number of rows: 10842
Number of columns: 13
for row in app_data_G [1:] :
print(row[10472])

IndexErrorTraceback (most recent call last)
in ()
1 for row in app_data_G [1:] :
----> 2 print(row[10472])

IndexError: list index out of range

len(app_data_G)
print(app_data_G[10472])
print(app_data_G[10473])
del app_data_G[10473]
len(app_data_G)
After reviewing few lines of data in the Google Store list, we discovered there were multiple entries of a single app. Some Examples are below

duplicate_apps =
unique_apps =

for app in app_data_G:
name = app[0]
if name in unique_apps:
duplicate_apps.append(name)
else:
unique_apps.append(name)

print(‘Number of duplicate apps:’, len(duplicate_apps))
print(’\n’)
print(‘Examples of duplicate apps:’, duplicate_apps[:5])

Number of duplicate apps: 1181

Examples of duplicate apps: [‘Quick PDF Scanner + OCR FREE’, ‘Box’, ‘Google My Business’, ‘ZOOM Cloud Meetings’, ‘join.me - Simple Meetings’]
I do not want to remove the duplicates. Instead, I will only leave behind the apps with the highest number of reviews because they represent the latest number of users.

reviews_max = {}

for app in app_data_G [1:] :
name = app [0]
n_reviews = float(app[3])
if name in reviews_max and reviews_max[name] < n_reviews :
reviews_max[name] += 1
if name not in reviews_max :
reviews_max[name] = 1

print(‘Length of reviews max dictonary:’, len(reviews_max))

ValueErrorTraceback (most recent call last)
in ()
3 for app in app_data_G [1:] :
4 name = app [0]
----> 5 n_reviews = float(app[3])
6 if name in reviews_max and reviews_max[name] < n_reviews :
7 reviews_max[name] += 1

ValueError: could not convert string to float: ‘3.0M’

andriod_clean =
already_added =

for app in app_data_G [1:]:
name = app[0]
n_reviews = float(app[3])
if (reviews_max[name] == n_reviews) and (name not in already_added) :
andriod_clean.append(app)
already_added.append (name)

print (andriod_clean[:3])
explore_data(andriod_clean, 0, 3,True)

def english (string):
non_ascii = 0
for character in string :

    if ord(character) > 127 :
        non_ascii += 1
if non_ascii > 3 :
    return False
else:
    return True


print (english (‘Instagram’))

print( english(‘爱奇艺PPS -《欢乐颂2》电视剧热播’) )

print ( english (‘Docs To Go™ Free Office Suite’))

print (english (‘Instachat :stuck_out_tongue_winking_eye:’))





english_google =
english_apple =

for app in andriod_clean :
name = app [0]
if english (name) :
english_google.append(app)

for app in app_data_A :
name = app [1]
if english (name):
english_apple.append(app)

explore_data (english_google, 0, 3, True)
print (’\n’)
explore_data (english_apple, 0, 3, True)

Hello @hillary.yeboah,

Your code is not properly formatted. When you post a well-formatted piece of code it is easier for people to help you. If you don’t know how to that, take a look at the Technical Question Guidelines for the community.

However, while going through your code, I noticed this IndexError was raised before the ValueError:

Typing print(app_data_G[10472]) will do the job instead of using a for loop.

After effecting the change, then do this:

If it doesn’t work this time, format your code properly and let me know.

Regards,

1 Like