I´m currently doing a project for university in which I need to evaluate a dataset from Kaggle: enter image description here
My problem is pretty simple, but I just couldn´t figure it out by researching: How can I make a comparision if the salary is higher or lower than 50K in Python? The problem is in the line of the 'if-clause'. It always shows me this error: IndexError: string index out of range
Thank you very much for helping me out!
import csv
with open('C:/Users/jkhjkh/Google Drive/Big data/adult.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
y = 0
z = 0
ages = []
maritalstatuss = []
races = []
sexes = []
hoursperweeks = []
incomes = []
for 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))
for x in range(1,len(ages)):
if ages[x] > '40' and ages[x] < '66' and income[x] < '50K':
y = y + 1
print(y)