# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +

def read_csv(S):
    f= open(S,'r')
    data = f.read()
    data_list = data.split("\n")
    string_list = data_list[1:-1]
    #print(d)
    #for i in d :
    final_list = []
    for i in string_list :
        int_fields = []
        string_fields = i.split(',')
        for y in string_fields :
            x = int(y)
            int_fields.append(x)
        final_list.append(int_fields) 
        for x in final_list:
            

    return final_list

# +

cdc_list = read_csv("US_births_1994-2003_CDC_NCHS.csv")
print(cdc_list[:10])

    

    

# +
def month_births(l) :
    births_per_month = {}
    for i in l :
        month =i[2]
        births = i[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)
print(cdc_month_births)


# +
def dow_births(l) :
    births_per_month = {}
    for i in l :
        month =i[3]
        births = i[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_day_births = dow_births(cdc_list)
print(cdc_day_births)


# +
def calc_counts(data, column):
    births_per_month = {}
    if column==3 :
        for i in data :
            month =i[column]
            births = i[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
    if column==2:
        for i in data :
            month =i[column]
            births = i[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
    if column==1:
        for i in data :
            month =i[column]
            births = i[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
    if column == 0 :
        for i in data :
            month =i[column]
            births = i[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_year_births = calc_counts(cdc_list,0)
print(cdc_year_births)

cdc_month_births = calc_counts(cdc_list,1)
#print(cdc_month_births)

cdc_dom_births = calc_counts(cdc_list,2)
#print(cdc_dom_births)

cdc_dow_births = calc_counts(cdc_list,3)
#print(cdc_dow_births)
# -



StarcoderdataJupyterScriptsDedupFiltered