import csv


def csv_file_to_nested_dict(filename, primary_key_col):
    """
    assumes the first line of the csv is column names. loads each line
    into a dict of kvps where key is column name and value is the value 
    in the cell.

    Puts all of these kvp dicts into one top level dict, where the key
    is the value of the 'primary_key_col' and the value is the kvp dict.
    """
    nested_dict = dict()
    with open(filename) as csvfile:
        reader = csv.DictReader(csvfile)
        for row_dict in reader:
            primary_key = row_dict[primary_key_col]
            nested_dict[primary_key] = row_dict
    #logger.log('loaded csv file to nested dict: ' + filename)
    #logger.pretty_print_jdata(nested_dict)
    return nested_dict