I'm trying to create a program where I take a user input and see if it is in a specific column (the 10th column) in a CSV file, then print out the entire row in which the input is found. I'm mostly having trouble on the code for matching the string to any values in a column.
city = input("Enter a city name: " ).upper()
with open('file.csv','rt') as file:
reader = csv.reader(file, delimiter=' ' )
for row in reader:
if city == row[9]:
print(row)
else:
print(input("City not in file. Enter a city name: "))
break
The CSV file looks like:
ID,Date,Age,Sex,Race,City...
1,06/08/2004,32,F,White,Denver
2,06/23/2004,23,M,Black,Hartford
.
.
.
I shortened it so I'm not listing everything, but the city column in the CSV would be the 10th column, not the 6th as above.