313-10 The elif clause, not returning desired results outside of DQ platform

Screen Link:

My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

for app in apps_data[1:]:
    price = float(app[4])
    if price == 0:
        app.append('free')
    elif price > 0 and price < 20:
        app.append('affordable')
    elif price >= 20 and price < 50: 
        app.append('expensive')
    elif price >= 50: 
        app.append('very expensive')

apps_data[0].append('price_label')

What I expected to happen: When run in Jupyter Notebook, this code does not return the actual price categories in the ‘if-statement.’ i.e. It does not create a new entry for each app which tells you if the app is free, expensive, etc… I’m wondering if this is accurate outside of the DQ platform, i.e. in the real world.

What actually happened:


When run in Jupyter Notebook, this code does not return the actual price categories specified in the 'if-statement.' i.e. It does not create a new entry for each app which tells you if the app is free, expensive, etc... I'm wondering if this is accurate outside of the DQ platform, i.e. in the real world.

Hi @zhcns.nj, welcome to the community!

I copied your code into Jupyter Notebook and it seems to be doing working as intended. I added print(apps_data[:3]) to the end of the code to check out the result, and it gave this as output:

[['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', 'price_label'], 
['284882215', 'Facebook', '389879808', 'USD', '0.0', '2974676', '212', '3.5', '3.5', '95.0', '4+', 'Social Networking', '37', '1', '29', '1', 'free'], 
['389801252', 'Instagram', '113954816', 'USD', '0.0', '2161558', '1289', '4.5', '4.0', '10.23', '12+', 'Photo & Video', '37', '0', '29', '1', 'free']]

If you add a print statement, is it showing something different?

1 Like

Thank you April. I think I was incorrectly splitting up the code in Jupyter Notebook, instead of putting it all in one block.

1 Like

Hi @zhcns.nj,

In Jupyter notebook, there are two ways to print data:

  1. Using print function
  2. Writing the name of the variable(that you want to print) in the last line of the cell

In your cell code, your last line is:

which is a transformation. So, jupyter is applying the transformation but since you have neither written print(app_data) nor app_data in the last line of your cell, hence it is not displaying any output.

If you add print(app_data) or app_data after apps_data[0].append(‘price_label’), then that will give you your required output.

I hope this makes sense.

1 Like