Python 3 Comparison String from Kaggle Dataset CSV-data: Error 'string index out of range python' -


i´m doing project university in need evaluate dataset kaggle: enter image description here

my problem pretty simple, couldn´t figure out researching: how can make comparision if salary higher or lower 50k in python? problem in line of 'if-clause'. shows me error: indexerror: string index out of range

thank helping me out!

import csv  open('c:/users/jkhjkh/google drive/big data/adult.csv') csvfile:     readcsv = csv.reader(csvfile, delimiter=',')  y = 0 z = 0  ages = [] maritalstatuss = [] races = [] sexes = [] hoursperweeks = [] incomes = []  row in readcsv:         # 4th row extracts     age = row[0]            # '54'     maritalstatus = row[5]  # 'divorced'     race = row[8]           # 'white'     sex = row[9]            # 'female'     hoursperweek = row[12]  # '40'     income = row[14]        # '<=50k'      ages.append(age)     maritalstatuss.append(maritalstatus)     races.append(race)     sexes.append(sex)     hoursperweeks.append(hoursperweek)     incomes.append(hoursperweek)  print(len(ages))  x in range(1,len(ages)):      if ages[x] > '40' , ages[x] < '66' , income[x] < '50k':         y = y + 1  print(y) 

i believe you're mistaken doing string comparison, though intend age (number) , income (number) comparison.

if (ages[x] > 40 , ages[x] < 66) , income[x] < 50000: 

make sure (age , income) python lists numeric. use conversion method. let me know if works.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -