I have a csv file that I am trying to read into python and then I want to store the first two columns in a variable called name and gender. The current code I am using is the following:
import csv
infile = open('blue.csv', 'r')
csvfile = csv.reader(infile)
name = []
gender = []
for row in csvfile:
name.append(row[0])
gender.append(row[1])
There are two problems I am encountering:
1) The csv file has headers so I don't want those included inside the variables when I store the columns
2) I am missing the gender for the last row of the csv file and so I don't want to include the last line of the csv file when I store it in a variable.
I am an R programmer and so to me, the way I would get around this is to read in the file excluding the first row and last row but I am unsure of how to do this in python, or better yet, if there is a better/smarter alternative.
If it helps, here is what a mock dataset would look like:
Name, Gender
Bob, Male
Susan, Female
Doug,