<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 GP02
Step1:  2
Step2:  3
Step3:  4
Step4:  5
<ASSISTANT_TASK:>
Python Code:
csv_list = open("../data/GP02/US_births_1994-2003_CDC_NCHS.csv").read().split("\n")
csv_list[0:10]
Explanation: GP02: Explore U.S. Births
The raw data behind the story Some People Are Too Superstitious To Have A Baby On Friday The 13th, which you can read here. 
We'll be working with the data set from the Centers for Disease Control and Prevention's National National Center for Health Statistics. 
The data set has the following structure:
* year - Year
* month - Month
* date_of_month - Day number of the month
* day_of_week - Day of week, where 1 is Monday and 7 is Sunday
* births - Number of births
1: Introduction To The Dataset
Lets explore the data and see how it looks.
End of explanation
def read_csv(filename):
    string_data = open(filename).read()
    string_list = string_data.split("\n")[1:]
    final_list = []
    
    for row in string_list:
        string_fields = row.split(",")
        int_fields = []
        for value in string_fields:
            int_fields.append(int(value))
        final_list.append(int_fields)
    return final_list
        
cdc_list = read_csv("../data/GP02/US_births_1994-2003_CDC_NCHS.csv")
cdc_list[0:10]
Explanation: 2: Converting Data Into A List Of Lists
The lists needs to be converted to a more structured format to be able to analyze it.
End of explanation
def month_births(data):
    births_per_month = {}
    
    for row in data:
        month = row[1]
        births = row[4]
        if month in births_per_month:
            births_per_month[month] = births_per_month[month] + births
        else:
            births_per_month[month] = births
    return births_per_month
    
cdc_month_births = month_births(cdc_list)
cdc_month_births
Explanation: 3: Calculating Number Of Births Each Month
Now that the data is in a more usable format, we can start to analyze it.
End of explanation
def dow_births(data):
    births_per_dow = {}
    
    for row in data:
        dow = row[3]
        births = row[4]
        if dow in births_per_dow:
            births_per_dow[dow] = births_per_dow[dow] + births
        else:
            births_per_dow[dow] = births
    return births_per_dow
    
cdc_dow_births = dow_births(cdc_list)
cdc_dow_births
Explanation: 4: Calculating Number Of Births Each Day Of Week
Let's now create a function that calculates the total number of births for each unique day of the week.
End of explanation
def calc_counts(data, column):
    sums_dict = {}
    
    for row in data:
        col_value = row[column]
        births = row[4]
        if col_value in sums_dict:
            sums_dict[col_value] = sums_dict[col_value] + births
        else:
            sums_dict[col_value] = births
    return sums_dict
cdc_year_births = calc_counts(cdc_list, 0)
cdc_month_births = calc_counts(cdc_list, 1)
cdc_dom_births = calc_counts(cdc_list, 2)
cdc_dow_births = calc_counts(cdc_list, 3)
cdc_year_births
cdc_month_births
cdc_dom_births
cdc_dow_births
Explanation: 5: Creating A More General Function
It's better to create a single function that works for any column and specify the column we want as a parameter each time we call the function.
End of explanation
<END_TASK>