"TypeError: list indices must be integers, not str" in Python 2.7
Question: I'm currently taking a Data Analysis course on Udacity. I'm having a bit of
hard time. I have I'm currently trying to convert some data types in some
dictionaries and I keep getting the error "TypeError: list indices must be
integers, not str" Now, it says it's a list but from my understanding all my
data is in a dictionary. Here's the code.

    
    
    # Lesson 1 - Data Analysis
    # Get & Open Data
    import unicodecsv
    import datetime as dt
    
    def openCSV(filename):
        with open(filename, "rb") as f:
            reader = unicodecsv.DictReader(f)
            return list(reader)
    
    def parse_date(date):
        if date == '':
            return None
        else:
            return dt.strptime(date, "%y-%m-%d")
    def parse_int(i):
        if i == '':
            return None
        else:
            return int(i)
    
    enrollments = openCSV("enrollments.csv")
    
    for enrollment in enrollments:
        enrollments['cancel_date'] = parse_date(enrollments['cancel_date'])
        enrollments['days_to_cancel'] = parse_int(enrollments['days_to_cancel'])
        enrollments['is_canceled'] = enrollments['is_canceled'] == 'True'
        enrollments['is_udacity'] = enrollments['is_udacity'] == 'True'
        enrollments['join_date'] = parse_date(enrollments['join_date'])
    
    # daily_engagement = openCSV("daily_engagement.csv")
    # project_submissions = openCSV("project_submissions.csv")
    
    enrollments[0]
    

Here is a sample of the contents of the file, it's the first two rows:

    
    
    account_key,status,join_date,cancel_date,days_to_cancel,is_udacity,is_canceled
    448,canceled,2014-11-10,2015-01-14,65,True,True
    


Answer: in your for loop, you get enrolment by iterating on enrolments, but you try to
access enrollments keys instead of enrollment keys

    
    
    for enrollment in enrollments:
        enrollment['cancel_date'] = parse_date(enrollment['cancel_date'])
        enrollment['days_to_cancel'] = parse_int(enrollment['days_to_cancel'])
        enrollment['is_canceled'] = enrollment['is_canceled'] == 'True'
        enrollment['is_udacity'] = enrollment['is_udacity'] == 'True'
        enrollment['join_date'] = parse_date(enrollment['join_date'])
    

Also, your helper functions can be simplified:

    
    
    def parse_date(date):
        return dt.strptime(date, "%y-%m-%d") if date else None
    
    def parse_int(i):
        return int(i) if i else None
    

